0.0.8 • Published 6 years ago

@jimengio/rex-legacy v0.0.8

Weekly downloads
-
License
ISC
Repository
-
Last release
6 years ago

Rex(Legacy)

Rex compatible library for migration old project.

Store abstraction based on immer and OLD Context APIs.

Usage

npm.io

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

0.0.8

6 years ago

0.0.8-a1

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago