clean-state
Advanced tools
Comparing version 2.1.2 to 2.1.3
@@ -61,2 +61,4 @@ export interface Module { | ||
export type Plugin = (modules: any, on: any) => void; | ||
export const mixin: <C extends Module, M extends Record<string, Module>>( | ||
@@ -63,0 +65,0 @@ common: C, |
import { useEffect, useCallback, useState } from 'react'; | ||
import EventEmitter from 'eventemitter3'; | ||
import Container from './container'; | ||
var DISPATCH_TYPE = Symbol('CS_DISPATCH'); | ||
var plugins = []; | ||
var bootstrap = function (modules) { | ||
var container = new Container(modules); | ||
var pluginEmitter = new EventEmitter(); | ||
var dispatch = function (nameAndMethod, payload) { | ||
@@ -11,2 +15,6 @@ var _a = nameAndMethod.split('/'), namespace = _a[0], methodName = _a[1]; | ||
if (effects[methodName]) { | ||
pluginEmitter.emit(DISPATCH_TYPE, { | ||
type: nameAndMethod, | ||
payload: payload | ||
}); | ||
return effects[methodName]({ state: state, payload: payload, rootState: rootState, dispatch: dispatch }); | ||
@@ -18,5 +26,10 @@ } | ||
rootState: rootState, | ||
payload: payload | ||
}); | ||
container.setState(namespace, newState); | ||
pluginEmitter.emit(DISPATCH_TYPE, { | ||
type: nameAndMethod, | ||
payload: payload, | ||
newState: newState | ||
}); | ||
container.setState(namespace, newState); | ||
} | ||
@@ -51,4 +64,9 @@ }; | ||
injectFns(rootEffects); | ||
plugins.forEach(function (plugin) { return plugin(modules, pluginEmitter.on); }); | ||
return { useModule: useModule, dispatch: dispatch }; | ||
}; | ||
bootstrap.addPlugin = function (plugin) { | ||
plugins.push(plugin); | ||
}; | ||
bootstrap.DISPATCH_TYPE = DISPATCH_TYPE; | ||
export default bootstrap; |
@@ -28,3 +28,3 @@ import EventEmitter from 'eventemitter3'; | ||
reducers: _this.rootReducers[k], | ||
effects: _this.rootEffects[k], | ||
effects: _this.rootEffects[k] | ||
}; | ||
@@ -31,0 +31,0 @@ Object.assign(combineModule, (_a = {}, _a[k] = module, _a)); |
{ | ||
"name": "clean-state", | ||
"version": "2.1.2", | ||
"version": "2.1.3", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -29,2 +29,3 @@ <p align="right"> | ||
7. TypeScript friendly and automatically deduces module types. | ||
8. Perfect support for RN. | ||
@@ -79,2 +80,6 @@ ## Installation | ||
function App() { | ||
/** | ||
* Here you can also pass in an array and return multiple module states at the same time | ||
* const {user, project} = useModule(['user', 'project']) | ||
*/ | ||
const { user } = useModule('user') | ||
@@ -81,0 +86,0 @@ const onChange = useCallback((e)=> { |
{ | ||
"compilerOptions": { | ||
"target": "es5", | ||
"target": "es3", | ||
"module": "esnext", | ||
@@ -5,0 +5,0 @@ "moduleResolution": "node", |
18355
314
205