@jimengio/rex-legacy
v0.0.8
Published
Data wrapper
Downloads
9
Readme
Rex(Legacy)
Rex compatible library for migration old project.
Store abstraction based on immer and OLD Context APIs.
Usage
npm install @jimengio/rex-legacy
Model:
export interface IGlobalStore {
schemaVersion: string;
data: number;
branchData: number;
homeData: number;
}
export let initialStore: IGlobalStore = {
schemaVersion: "0.1",
data: 2,
branchData: 2,
homeData: 2,
};
import { createStore } from "rex";
export let globalStore = createStore<IGlobalStore>(initialStore);
View:
import { RexProvider } from "rex";
const renderApp = () => {
ReactDOM.render(
<RexProvider value={globalStore}>
<Container store={globalStore.getState()} />
</RexProvider>,
document.querySelector(".app")
);
};
window.onload = () => {
renderApp();
globalStore.subscribe(renderApp);
};
Controller:
export function doIncData() {
globalStore.update((store) => {
store.data += 1;
});
}
Selector:
import { connectRex } from "rex";
@connectRex((store: IGlobalStore, ownProps: IProps) => ({ data: store.data }))
export default class Inside extends React.PureComponent<IProps, IState> {
render() {
return <div />;
}
}
Workflow
https://github.com/jimengio/ts-workflow
License
MIT