Code Monkey home page Code Monkey logo

stook's Issues

针对 useStore,能否加一个泛型来约束 key 值

export const StoreKey = {
  a: 'a',
  b: 'b',
  c: 'c',
};

export type StoreKeyType = keyof typeof StoreKey;

使用的时候就可以提示可选的 store 值

useStore<StoreKeyType>('x', 0) // 这样就会报错,因为 x 不在 StoreKey 中

这样一方面能够有提示,另一方对大型项目可以作为相应的约束参照

useFetch 与useEffect 是否不同

我使用 useFetch 获取页面数据,在我首次进入这个页面的时候,useFetch 是工作的,但是当我第二次进入的时候,useFetch 不工作了,但是useEffect 还会继续工作,请问这两者更新有什么不同呢?

useStore能否支持useSelector

目前的useStore只要组件订阅了key, setState之后就会将发布订阅队列全部执行渲染,即使组件中没有用到store中的某些数据,能否实现类似redux的useSelector式API呢,另外还有一个问题就是目前这种方案,useStore中的数据初始化是在第二个参数中,两个组件订阅相同的key,初始化的数据将会以第一个先订阅为准,这样没约束规范吧,是否需要加一个store初始化的步骤呢

初始值依赖组件的渲染顺序??

import * as React from "react";
import { render } from "react-dom";
import { useStore } from "stook";

function Display() {
  const [count] = useStore("Counter", 100);
  return <p>{count}</p>;
}


function Counter() {
  const [count, setCount] = useStore("Counter", 8);
  return (
    <div>
      <p>You clicked {count} times</p>
      <button onClick={() => setCount(count + 1)}>Click me</button>
    </div>
  );
}

// 调整 Display Counter 的位置会得到不同的初始值
function App() {
  return (
    <div>
      <Display />
      <Counter />
    </div>
  );
}

const rootElement = document.getElementById("root");
render(<App />, rootElement);

这种设计方式很容易出bug吧.....

by the way ,可以了解下Concent:
https://github.com/concentjs/concent

一个渐进式&高性能的增强型状态管理方案

可以在React组件外部订阅状态更新吗?

这个项目挺好的,但是有个问题,目前我使用Redux一部分原因是为了实现React内和外部另外一个渲染程序(WebGL)的数据双向绑定的,看了下API文档,好像在外部只能读取指定状态,没法订阅更新.
或者提供个Api,直接暴露原始Redux的stroe对象.:joy:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.