redux-anno
TypeScript icon, indicating that this package has built-in type declarations

0.0.9 • Public • Published

Redux Anno

A middleware leverages certain boilerplate while using redux

npm version Build Status Coverage Status Code style

This is a very early release of this package, do not suggest using it in production till latter stable version

I am a good old fan of spring core context DI and redux-anno is my first try to set up something similar in the Redux World.

A Simple Counter Example showing what I am trying to do

import {Model, State, Saga, createState, initReduxAnno, getContext} from 'redux-anno';

import {putResolve} from 'redux-saga/effects';

@Model()
export class Counter {
  @State
  count = createState(0 as number);

  @Saga()
  *updateCount(nextVal: number) {
    yield putResolve(this.count.create(nextVal));
  }
}

describe('CounterModel', () => {
  beforeAll(() => {
    initReduxAnno({
      entryModel: Counter,
    });
  });

  it('counter 01', async () => {
    const defaultCtx = getContext();
    const counterInst = defaultCtx.getOneInstance(Counter);

    expect(counterInst.count.value).toBe(0);

    await counterInst.updateCount.dispatch(1);

    expect(counterInst.count.value).toBe(1);
  });
});

For more info and details, please check the sample application examples/react-sample-app for now;

More detailed docs are incoming~

Readme

Keywords

Package Sidebar

Install

npm i redux-anno

Weekly Downloads

0

Version

0.0.9

License

MIT

Unpacked Size

257 kB

Total Files

45

Last publish

Collaborators

  • albertli90