1.0.10 • Published 1 year ago

redux-effects-promise v1.0.10

Weekly downloads
140
License
MIT
Repository
github
Last release
1 year ago

redux-effects-promise

An implementation of declarative promises effects for redux. The solution is based on inversify library.

Installation

npm install redux-effects-promise --save

Dependencies

Usage

import 'reflect-metadata';
import { createStore } from 'redux';
import { Container } from 'inversify';
import { EffectsService, effectsMiddleware } from 'redux-effects-promise';

export const middlewares = [..., effectsMiddleware];
EffectsService.configure(new Container(), createStore(...));
import { EffectsService } from 'redux-effects-promise';
...
@provide(DashboardListEffects)
export class DashboardListEffects {
	...
	@EffectsService.effects('dashboard.list.load')
	loadProducts(): Promise<IProduct[]> {
		return this.api.loadProducts();
	}

    // Or ...
    // @EffectsService.effects('dashboard.list.load')
    // loadProducts(): IProduct[] {
    //    return [{ name: 'Product1', id: 1901 }, { name: 'Product2', id: 1902 }];
    // }
}
import { AnyAction } from 'redux';
import { EffectsAction, EffectsService } from 'redux-effects-promise';
...
@provide(DashboardFormEffects)
export class DashboardFormEffects {
    ...
	@EffectsService.effects('dashboard.form.submit')
	saveProduct(action: AnyAction, state: IAppState): Promise<EffectsAction[]> {
		return this.api.saveProduct(action.data)
			.then(result => {
				return [
					EffectsAction.create('dashboard.form.submit.done', result),
					EffectsAction.create('dashboard.list.update', action.data),
					EffectsAction.create('dashboard.back', action.data)  // Parameter1=action.data
				];
			});
	}

	@EffectsService.effects('dashboard.back')
	back(): EffectsAction[] {
		// A inheriting of the parameters works finely so input parameter
		// "Parameter1" would pass within an action = { type: ..., data: ..., initialData: Parameter1 }
		return [
			EffectsAction.create('dashboard.list.deselect'),
			EffectsAction.create('router.navigate', '/dashboard')
		];
	}
}

Preview

00

License

Licensed under MIT.

1.0.10

1 year ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.0.22

6 years ago

0.0.21

6 years ago

0.0.20

6 years ago

0.0.19

6 years ago

0.0.18

6 years ago

0.0.17

6 years ago

0.0.16

7 years ago

0.0.15

7 years ago

0.0.14

7 years ago

0.0.13

7 years ago

0.0.12

7 years ago

0.0.11

7 years ago

0.0.10

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago