npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@rasir/jotai-redux

v0.0.10

Published

封装jotai模拟redux-saga的api

Downloads

7

Readme

@rasir/jotai-redux

封装 jotai 模拟 redux-saga 的 api

使用方法

// APIs
import {
  select,
  useSelector,
  useUpdateStore,
  useDispatch,
  createStore,
  updateState,
  getStore,
  addStores,
  dispatch,
} from "@rasir/jotai-redux";
    1. createStore 用于初始化 store
const store = createStore({
  states: {
    user: { id: 1, name: "rasir" },
  },
  actions: {
    user: {
      update:async ({type:"user/update",payload},{select,put,update,all}) => {
        const {id} = select(({user}) => user);
        if(id === payload.id){
         await all([
            put({type:"user/updateName",payload:payload.name}),
            put({type:'user/updateId',payload:payload.id})
          ])
        }
      },
      updateName:async ({type:"user/updateName",payload},{select,put,update,all}) => {
        await update('user',{name:payload});
      },
       updateId:async ({type:"user/updateId",payload},{select,put,update,all}) => {
         await update('user',{id:payload});
      },
    },
  },
});
    1. addStores 用于添加 store。参数与createStore相同,不同点在于,addStores 会合并到已有的 store
addStores({
  states: { todo: { id: 1, name: "todo1" } },
  actions: { todo: { update: () => {} } },
});
    1. updateState 用于更新 store 中某个 state
updateState("user", { name: "rasir2" });
    1. getStore 用于获取 store 中所有的 state
const store = getStore();
    1. useSelector 用于获取 store
const user = useSelector(({ user }) => user);
    1. useUpdateStore 用于更新 store
const update = useUpdateStore("user");
update({ name: "rasir2" });
    1. select 用于获取 store
const user = useSelector(({ user }) => user);
    1. useDispatch 用于获取 dispatch
const dispatch = useDispatch();
dispatch({ type: "user/update", payload: { id: 2, name: "rasir2" } });
    1. dispatch 用于获取触发 action 的方法
dispatch({ type: "user/update", payload: { id: 2, name: "rasir2" } });
    1. 高阶组件(HOC)connect 类似于 react-redux 的 connect,用于将 store 中的 state 和 dispatch 与组件进行绑定
const App = ({ name, update }) => {
  return (
    <button onClick={() => update({ id: 1, name: "rasir2" })}>{name}</button>
  );
};
export default connect(
  ({ user: { name } }) => ({ name }),
  (dispatch) => ({
    update: (payload) => dispatch({ type: "user/update", payload }),
  })
)(App);

jotai 原有 api 均可直接使用