Skip to content

Commit

Permalink
feat: 优化首页
Browse files Browse the repository at this point in the history
  • Loading branch information
fancyzhong committed Sep 3, 2024
1 parent e70a72a commit d572571
Show file tree
Hide file tree
Showing 17 changed files with 350 additions and 32 deletions.
26 changes: 26 additions & 0 deletions docs/.dumi/theme/builtins/ContactAuthor/Features.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import './index.less';

function Feature(props: any) {
const { title, description, imgSrc } = props.item;
return (
<div className="dumi-default-features-item hx-feature-item">
<div style={{ textAlign: 'center' }}>
<img src={imgSrc} style={{ width: '88px', height: '88px' }} />
</div>
<span style={{ color: 'rgb(100, 90, 183)' }} >
<h2>{title}</h2>
</span>
<span style={{ color: 'gray' }}>
<p>{description}</p>
</span>
</div>
)
}

export function Features(props: any) {
return (
<div className="dumi-default-features" data-cols="3" style={{ padding: 0 }}>
{props.featureList.map((v: any) => <Feature key={v.title} item={v} />)}
</div>
);
}
8 changes: 8 additions & 0 deletions docs/.dumi/theme/builtins/ContactAuthor/index.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.hx-feature-item {
box-shadow: rgba(0, 0, 255, 0.2) 1px 2px 2px 1px;
background-color: rgb(255, 255, 255);
border-radius: 6px;
padding: 24px;
box-sizing: border-box;
height: 270px;
}
44 changes: 44 additions & 0 deletions docs/.dumi/theme/builtins/ContactAuthor/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,51 @@
import React, { type FC } from 'react';
import { SimplePlayground } from '../../../../docs/playground/demos/Playground';
import { Features } from './Features';


const imgs = [
'https://tnfe.gtimg.com/image/harzqyxcgz_1651755973579.png',
'https://tnfe.gtimg.com/image/p40w0k40pt_1651755965504.png',
'https://tnfe.gtimg.com/image/fxy2nbeh43_1651755969439.png',
'https://tnfe.gtimg.com/image/bxzj46o32k_1651755962175.png',
'https://tnfe.gtimg.com/image/ngex07gcez_1651755956158.png',
'https://tnfe.gtimg.com/image/harzqyxcgz_1651755973579.png',
];
function getImg(idx: number) {
return imgs[idx] || imgs[0];
}
const featureList = [
{
title: 'atom',
description: 'atom 支持任意数据结构,对非原始类型数据内置依赖收集功能, 意味着 atom 不用拆分的很细,天然对 DDD 领域驱动设计友好',
},
{
title: 'signal',
description: '内置 signal 响应机制,可实现 0 hook 编码 + dom 粒度的更新',
},
{
title: '依赖追踪',
description: '基于最快的不可变 js 库 limu 做到运行时对视图渲染实时收集数据依赖,提供超强渲染性能',
},
{
title: 'reactive',
description: '提供全局响应式对象,数据变更直接驱动关联ui渲染(默认在下一个事件循环微任务开始前提交,支持人工提交变更数据)',
},
{
title: 'modular',
description: '支持对状态模块化抽象,并内置 actions、derive、watch、loading 等特性,轻松驾驭大型前端应用架构',
},
{
title: 'middleware&plugin',
description: '内置中间件和插件系统,无缝衔接redux生态优秀组件',
},
];
featureList.forEach((v: any, idx: number) => v.imgSrc = getImg(idx));

const ContactAuthor: FC = () => (
<div style={{ width: '100%' }}>
<SimplePlayground />
<Features featureList={featureList} />
<div style={{ width: '48%', display: 'inline-block' }}>
<h4>📦 了解更多</h4>
<p>
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/api/atom-ctx/use-state-x.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ order: 1
---

:::info
更多用法查阅[Hooks/useAtomX](/api/hooks/use-atom-x)
更多用法查阅[Hooks/useAtomX](/api/hooks/use-atomx)
:::
4 changes: 2 additions & 2 deletions docs/docs/api/base/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ nav:
包含以下基础函数

- [atom](/api/base/atom) 创建`atom`对象,返回元组
- [atomx](/api/base/atom-x) 创建`atom`对象,返回字典
- [atomx](/api/base/atomx) 创建`atom`对象,返回字典
- [share](/api/base/share) 创建字典型`atom`对象,返回元组
- [sharex](/api/base/share-x) 创建字典型`atom`对象,返回字典
- [sharex](/api/base/sharex) 创建字典型`atom`对象,返回字典
- [signal](/api/base/signal) 创建`signal`响应区域,实现dom粒度更新
- [block](/api/base/block) 创建`block`块响应区域,实现块粒度更新
- [dynamicBlock](/api/base/dynamic-block) 组件渲染过程中创建动态`block`块响应区域,实现块粒度更新
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/api/hooks/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ order: 0
包含以下常用钩子

- [useAtom](/api/hooks/use-atom) 使用`atom`对象,返回元组
- [useAtomX](/api/hooks/use-atom-x) 使用`atom`对象,返回字典
- [useAtomX](/api/hooks/use-atomx) 使用`atom`对象,返回字典
- [useReactive](/api/hooks/use-reactive) 使用`reactive`对象,返回元组
- [useReactiveX](/api/hooks/use-reactive-x) 使用`reactive`对象,返回字典
- [useDerived](/api/hooks/use-derived) 使用全量派生结果
Expand Down
6 changes: 3 additions & 3 deletions docs/docs/api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ nav:
- [基础](/api/base/atom)

> - [atom](/api/base/atom) 创建`atom`对象,返回元组
> - [atomx](/api/base/atom-x) 创建`atom`对象,返回字典
> - [atomx](/api/base/atomx) 创建`atom`对象,返回字典
> - [share](/api/base/share) 创建字典型`atom`对象,返回元组
> - [sharex](/api/base/share-x) 创建字典型`atom`对象,返回字典
> - [sharex](/api/base/sharex) 创建字典型`atom`对象,返回字典
> - [signal](/api/base/signal) 创建`signal`响应区域,实现dom粒度更新
> - [block](/api/base/block) 创建`block`块响应区域,实现块粒度更新
> - [dynamicBlock](/api/base/dynamic-block) 组件渲染过程中创建动态`block`块响应区域,实现块粒度更新
Expand Down Expand Up @@ -51,7 +51,7 @@ ctx.aciton()(/** action 函数定义 */)
- [Hooks](/api/hooks/)

> - [useAtom](/api/hooks/use-atom) 使用`atom`对象,返回元组
> - [useAtomX](/api/hooks/use-atom-x) 使用`atom`对象,返回字典
> - [useAtomX](/api/hooks/use-atomx) 使用`atom`对象,返回字典
> - [useReactive](/api/hooks/use-reactive) 使用`reactive`对象,返回元组
> - [useReactiveX](/api/hooks/use-reactive-x) 使用`reactive`对象,返回字典
> - [useDerived](/api/hooks/use-derived) 使用全量派生结果
Expand Down
18 changes: 5 additions & 13 deletions docs/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,11 @@ hero:
link: /playground
- text: Github
link: https://github.com/heluxjs/helux
features:
- title: atom
description: atom 支持任意数据结构,对非原始类型数据内置依赖收集功能, 意味着 atom 不用拆分的很细,天然对 DDD 领域驱动设计友好
- title: signal
description: 内置 signal 响应机制,可实现 0 hook 编码 + dom 粒度的更新
- title: 依赖追踪
description: 基于最快的不可变 js 库 limu 做到运行时对视图渲染实时收集数据依赖,提供超强渲染性能
- title: reactive
description: 提供全局响应式对象,数据变更直接驱动关联ui渲染(默认在下一个事件循环微任务开始前提交,支持人工提交变更数据)
- title: modular
description: 支持对状态模块化抽象,并内置 actions、derive、watch、loading 等特性,轻松驾驭大型前端应用架构
- title: middleware&plugin
description: 内置中间件和插件系统,无缝衔接redux生态优秀组件
# 此处已转移到 ContactAuthor 里的 Features 渲染
# features:
# - title: atom
# description: atom 支持任意数据结构,对非原始类型数据内置依赖收集功能, 意味着 atom 不用拆分的很细,天然对 DDD 领域驱动设计友好
# ...
---

<ContactAuthor barValue="Big Bar!"></Contact>
1 change: 1 addition & 0 deletions docs/docs/playground/demos/Playground/ApiMenus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as codes from './codes';
const c = '#e8ae56';

const orderedKeys = [
'quickStart',
'atom',
'derive',
'watch',
Expand Down
3 changes: 2 additions & 1 deletion docs/docs/playground/demos/Playground/Console.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react'
import * as helux from 'helux'
import { Hook, Console, Decode } from 'console-feed';
import './index.less';

Expand All @@ -11,7 +12,7 @@ class HeluxConsole extends React.Component<any, { logs: any[] }> {
Hook(window.console, (log) => {
this.setState(({ logs }) => ({ logs: [...logs, Decode(log)] }))
});
console.log('Welcome to helux playground ^_^');
console.log(`Welcome to helux playground (helux ver: ${helux.cst.VER})^_^`);
}

render() {
Expand Down
3 changes: 0 additions & 3 deletions docs/docs/playground/demos/Playground/TopBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ function renderItems(name: string, subName: string) {
));
}



export default React.memo(({ onClick, name, subName }: any) => {

const handleClick = e => {
const subName = e.target.dataset.name;
if (subName) {
Expand Down
1 change: 0 additions & 1 deletion docs/docs/playground/demos/Playground/codes/atom.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@


const primitive = `
const [ num, setNum ] = atom(1);
Expand Down
1 change: 1 addition & 0 deletions docs/docs/playground/demos/Playground/codes/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { default as quickStart } from './quickStart';
export { default as atom } from './atom';
export { default as derive } from './derive';
export { default as watch } from './watch';
Expand Down
171 changes: 171 additions & 0 deletions docs/docs/playground/demos/Playground/codes/quickStart.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
const HelloHelux = `
const [str, setStr, ctx] = atom('hello helux'); // define atom, str is boxed with {val:T} strcture
const reversedStr = derive(() => str.val.split('').reverse().join('')); // define derive
function HelloHelux(){
const [strVal] = useAtom(str); // strVal is auto unboxed
const [reversedStrVal] = useDerived(reversedStr);
return (<div>
<input value={strVal} onChange={e=>setStr(e.target.value)} />
<input value={strVal} onChange={ctx.syncer} />
<h1>reversed: {reversedStrVal}</h1>
</div> );
}
render(<HelloHelux />);
`;

const HelloHeluxDict = `
// no { val: T } wrapped with share api, so using share is better than atom at this situation
const [dict, setDict, ctx] = share({str: 'hello helux'}); // define share
const reversedStr = derive(() => dict.str.split('').reverse().join('')); // define derive
function HelloHeluxDict(){
const [dictState] = useAtom(dict);
const [reversedStrVal] = useDerived(reversedStr);
return (<div>
<input value={dictState.str} onChange={e=>setDict(draft=>draft.str=e.target.value)} />
<input value={dictState.str} onChange={ctx.syncer.str} />
<h1>reversed: {reversedStrVal}</h1>
</div> );
}
render(<HelloHeluxDict />);
`;

const DataBindWidthHook = `
const [num, setNum] = atom(1);
const numDouble = derive(() => num.val * 2); // derive num
const change = () => { // change num
setNum(prev => prev + 1);
};
function DataBindWidthHook() {
const [numVal] = useAtom(num);
const [numDoubleVal] = useDerived(numDouble);
return (
<div>
<h3>numVal {numVal}</h3>
<h3>numDoubleVal {numDoubleVal}</h3>
<button onClick={change}> change num </button>
</div>
);
}
render(<><DataBindWidthHook /><DataBindWidthHook /></>);
`;

const DataBindWidthNoHook = `
const [num, setNum] = atom(1);
const numDouble = derive(() => num.val * 2); // derive num
const change = () => { // change num
setNum(prev => prev + 1);
};
// pass primitive data to ui with $
function DataBindWidthNoHook() { // DOM granularity update
return (
<div>
<h3>numVal {$(num)} </h3>
<h3 > numDoubleVal {$(numDouble)} </h3>
<button onClick={change}> change num </button>
</div>
);
}
render(<><h1 style={{color:'red'}}>dom粒度更新</h1><DataBindWidthNoHook/></>);
`;

const DictDataBindWidthHook = `
// const [dict, setState] = atom({ a: 1, b: { b1: 1, b2: { b2_1: 'cool' } } });
// const numDouble = derive(() => dict.val.a + 100 ); // dict.val.a
// no { val: T } wrapped with share api, so using share is better than atom at this situation
const [dict, setState] = share({ a: 1, b: { b1: 1, b2: { b2_1: 'cool' } } });
const aPlus = derive(() => dict.a + 100 ); // dict.a
const change = () => { // change num
setState(prev => prev.a += 100 );
};
function DictDataBindWidthHook() {
const [dictState] = useAtom(dict);
const [aPlusVal] = useDerived(aPlus);
return (
<div>
<h3>dictState {dictState.a}</h3>
<h3>aPlusVal {aPlusVal}</h3>
<button onClick={change}> change num </button>
</div>
);
}
render(<DictDataBindWidthHook />);
`

const DictDataBindWidthNoHookUsingBlock = `
const [dict, setState] = share({ a: 1, b: { b1: 1, b2: { b2_1: 'cool' } } });
const aPlus = derive(() => dict.a + 100 ); // dict.a
const change = () => { // change num
setState(prev => prev.a += 100 );
};
// create a block component
const DictDataBindWidthNoHookUsingBlock = block(()=>(
<div>
<h3>dictState {dict.a}</h3>
<h3>aPlusVal {aPlus.val}</h3>
<button onClick={change}> change num </button>
</div>
));
render(<><h1 style={{color:'red'}}>block粒度更新</h1><DictDataBindWidthNoHookUsingBlock/></>);
`


const ChangeStateWithActions = `
const ctx = sharex({str: 'hello helux', asyncClicked: 0});
const delay = (ms=1000)=> new Promise(r=>setTimeout(r, ms));
const { actions, useLoading } = ctx.defineActions()({
// sync action
changeStr({ draft }) {
draft.str = \`changed at \${Date.now()}\`;
},
// async action
async changeStrAsync({ draft }) {
await delay();
draft.str = \`async changed at \${Date.now()}\`;
draft.asyncClicked += 1;
if(draft.asyncClicked === 3){
throw new Error('a fake error occurred!');
}
},
});
function ChangeStateWithActions(){
const [state] = ctx.useState();
const ret = useLoading();
const { changeStrAsync } = useLoading();
return (<div>
{changeStrAsync.loading && 'loading'}
{changeStrAsync.ok && <h1>str: {state.str}</h1>}
{changeStrAsync.err && <h1 style={{color:'red'}}>err: {changeStrAsync.err.message}</h1>}
<button onClick={actions.changeStr}>changeStr</button>
<button onClick={actions.changeStrAsync}>changeStrAsync( try click me 3 times )</button>
</div> );
}
render(<ChangeStateWithActions />);
`;

export default {
HelloHelux,
HelloHeluxDict,
DataBindWidthHook,
DataBindWidthNoHook,
DictDataBindWidthHook,
DictDataBindWidthNoHookUsingBlock,
ChangeStateWithActions,
} as Record<string, string>;
Loading

0 comments on commit d572571

Please sign in to comment.