Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TODO] 3.0.0设计 #2

Open
2 tasks done
sky0014 opened this issue Mar 22, 2022 · 2 comments
Open
2 tasks done

[TODO] 3.0.0设计 #2

sky0014 opened this issue Mar 22, 2022 · 2 comments

Comments

@sky0014
Copy link
Owner

sky0014 commented Mar 22, 2022

  • 支持按需导入
  • 支持computed
@sky0014
Copy link
Owner Author

sky0014 commented Mar 22, 2022

继续简化结构,不再使用id标识,类似这样:

const app = {
 todos: [],

 @computed
 get count() {
  return this.todos.length;
 },

 add(todo: string) {
  this.todos.push(todo);
 } 
}

使用时:

function App() {
-   // 按需导入(废弃原因1、需要固定的解构模式;2、复杂数据结构支持不太好)
-  const { todos, count, add } = useStore(app); 
+  // 按需导入,使用selector,可支持复杂数据,可利于依赖分析,可使用柯里化简化调用
+  const count = useStore(app, app => app.count);
   return <div onClick={()=>app.add('something')}>{count}</div>
}

在非react组件中:

const count = app.count;
app.add('123')

@sky0014
Copy link
Owner Author

sky0014 commented Apr 22, 2022

已完成,改动较大,重新写了另外一个库:https://github.com/sky0014/store ,适用于大型的需要多store的项目。

本项目本质上是对redux和immer的重新组合,技术上较为成熟,仍可继续使用。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant