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

tkit-redux-model

v3.2.5

Published

> TODO: description

Downloads

5

Readme


name: redux-model menu: 'redux' route: /tkit/redux-model

npm i tkit-redux-model

tkit createModel 封装,自原 tkit-model 分离出

1. API

- 1.3 createModel

创建全局 redux model

- 1.0.① CM

自版本 3.1.2 起, 创建集成 immer & 结合 [email protected]+ 自动实现 redux store namespace 隔离的 model

Example

userModel 本体

import { Tction, CM } from 'tkit-redux-model';

export const userModelState = {
  name: ''
};

export const UserModel = CM({
  state: userModelState,
  namespace: 'cmModel',
  reducers: {
    /** 写入名字 */
    doSetName: (state, action: Tction<string>) => {
      state.name = action.payload;
    }
  },
  effects: {}
});

initialState

// tkit-tkit auto-manage
import { userModelState } from './userModel';

const initialState = {
  userModel: userModelState
};

- 1.3.② createModel Effects

3.0.6版本起,Effects 提供了更友好的控制副作用开始、成功、失败交互效果的协议,结合[email protected]+运用,可以明显减轻开发负担

所有来自 Effects 的 async 副作用,在 async 内会标记为:

channel: 'tkit-model/effect'

{
  effects: {
    /** 显示全局的loading效果 */
    doSomethingWithLoading: [
      function*({ tPut, tCall }, action: Tction<{ id: string }>): Iterator<{}> {
        /** 抛出全局错误信息 */
        throw '操作失败';
        /** 抛出全局成功信息 */
        return '操作成功';
      },
      {
        type: 'takeEvery', // it all depends
        loading: true
      }
    ],
    *doSomethingAsync({ tPut, tCall }, action: Tction<{ id: string }>): Iterator<{}> {
      /**  抛出全局错误信息 */
      throw '操作失败';
    }
  }
}

- 1.3.③ 弹窗 Effects

可弹窗

import { doAsync } from 'tkit-async';
{
  effects: {
    /** 弹窗 */
    *doSometingPopAsync({ tPut, tCall }, action: Tction<{ title: string, formProps }>): Iterator<{}> {
      const { title, formProps } = action.payload;
      const res = yield doAsync({
        fetch: () => {},
        modalProps: {
          title
        },
        formProps,
        successMsg: false,
        errorMsg: false
      });
      if (res.code) {
        throw res.message || '操作失败';
      }
      return '操作成功';
    }
  }
}

Example

import createModel, { Tction }  from 'tkit-redux-model';
import otherModel from './otherModel';

const myModel = createModel({
  effects: *doSomethingAsync({ namespace, put, tPut }, action: Tction<{ username: string }>) {
    // 触发其他 model action
    // way 1, rec
    yield tPut(otherModel.actions.actionsNameA, { username: '' });
    // way 2
    yield put({ type: otherModel.TYPES.actionsNameA, payload: { username: '' } });

    // 出发本 model action
    // way 1, rec
    yield tPut(myModel.actions.actionsNameA, { username: '' });
    // way 2
    yield put({ type: myModel.TYPES.actionsNameA, payload: { username: '' } });
    // way 3
    yield put({ type: `${namespace}/actionsNameA`, payload: { username: '' } });
  }
})