1.3.2 • Published 6 years ago

awex v1.3.2

Weekly downloads
2
License
ISC
Repository
github
Last release
6 years ago

awex

针对小程序的状态管理工具

特性

  • 支持typescript
  • 使用简单
  • 支持模块
  • 支持异步action

example

初始化
import Store, { IOptions, IActions } from 'awex';
import apis, { ISystemInfo } from 'mp-apis';
import homeModel, { IHomeState, IHomeActions } from '../pages/home/store';

export interface IState {
    home?: IHomeState;
    systemInfo: ISystemInfo;
}

export interface IStoreActions extends IActions {
    home?: IHomeActions;
    getSystemInfo(): Promise<void>;
}

export default Store.createStore<IState, IStoreActions>({
    log: true,
    modules: {
        home: homeModel,
    },
    state: {
        systemInfo: {} as ISystemInfo,
    },
    actions: {
        getSystemInfo: async ({ state }) => {
            const system = await apis.getSystemInfo();
            state.systemInfo = system;
        },
    },
    setStorage: state => {
        const app = getApp();
        app.store = state;
    },
});
使用
import store from './store';

@Provider(store)
class MyApp implements AppOptions {
    onLaunch() {
        store.actions.getSystemInfo();
    }
}
App(new MyApp());
interface IData extends IHomeState {}

@store.connect(state => ({
    ...state.home!,
}))
class PageOptions {
    pageWillReceiveData(data: IData) {
        // console.log('change=>', data);
    }
    update = (data: Partial<IData>) => {
        store.actions.home!.updateState(data);
    };
}
1.3.2

6 years ago

1.3.1

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.6

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago