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

rectmox

v1.0.8

Published

rectmox

Downloads

4

Readme

Rectmox

Build Status NPM version node version npm download

安装

npm install rectmox or yarn add rectmox

特征

  • [x] 使用react最新的createContext Api
  • [x] 不依赖于任何其他库
  • [x] 和rematch具有相似的api
  • [x] 使用es6的proxy,使用起来更为简单

使用

在顶层用provide包裹,初始化store

import { init, Provide } from 'reactmox'
import React from 'react'
import ReactDOM from 'react-dom'
import App from './app.js

const count = {
  state: {number: 1},
  reducers: {
    increase:(state, payload) => {
      state.number += payload
    }
  },
  effects: {
    asyncIncrease: ({payload, dispatch}) => {
      new Promise(resolve => {
        setTimeout(() => {
            resolve();
        }, 2000);
      }).then(() => {
          dispatch({type: 'count/increment', payload });
      });
    }
  }
}

const store = init({count})

ReactDOM.render(
  <Provider store={store}>
    <App />
  </Provider>, 
  document.getElementById('root'));

app.js

import React, { Component } from 'react';
import { observe } from 'rectmox';

@observe({
    modelName: 'count',
    state: ['number'],
    reducers: ['increment', 'decrement'],
    effects: ['aysncIncrement']
})
class Demo extends Component {
    constructor(props) {
        super(props);
    }

    //两种方法都可以
    increment = () => {
        // this.store.dispatch({ type: 'count/increment', payload: 1 });
        const props = this.props;
        props.increment(1);
    }

    decrement = () => {
        const props = this.props;
        props.decrement(1);
        // this.store.dispatch({ type: 'count/decrement', payload: 1 });
    }

    asyncIncrease = () => {
        const props = this.props;
        props.aysncIncrement(1);
        //this.store.dispatch({ type: 'count/aysncIncrement', payload: 1 });
    }
    render() {
        const props = this.props;
        return (
            <div>
                <button onClick={this.increment}>点击增加</button>
                <button onClick={this.decrement}>点击减少</button>
                <button onClick={this.asyncIncrease}>异步增加</button>
                {props.number}
            </div>
        );
    }
}

export default Demo;

Api

init

init用来初始化model,每个model都是一个文件。多个model的话就可以写成
init({ model1, model2, model3, ...model})

store.dispatch()

store.dispath({type: 'modelName/function', payload: 1})
通过dispatch来更新state
modelName 为此模块的名称,比如模块名称叫count
function 即为reducers or effects的函数
可参照@observe的用法

observe

@observe({
  modelName: 'count',
  state: ['number'],
  reducers: ['increment', 'decrement'],
  effects: ['aysncIncrement']
})
observe()
参数为一个对象
{
  modelName: string
  state?: array
  reducers?: array
  effects?: array
}

store.getState

store.getState() 获取全部的state

model写法

const modelName = {
  state: { number1 },
  reducers: {
    function1: (state, payload) => {},
    function2: (state, payload) => {}
  },
  effects: {
    asyncFunction1: ({payload, dispatch, rootState }) => {},
    asyncFunction2: ({payload, dispatch, rootState }) => {}
  }
}

reducers中的state即为上下的state
effects里有一个对象参数,有payload, dispatch, rootState

开源协议

MIT