createStore function
- {List<
BaseState> states, - List<
BaseEffect> effects: const [], - bool enableGlobalApi: false}
This is the entry point of the ajwah store.
states
is a mandatory param. And it should not be null or empty.
effects
is an optional param.
enableGlobalApi
by default it is false
. If you pass true
then global
functions like dispatch(), select() etc should be exposed.
Also you can dynamically add or remove state and effect using addState(BaseState stateInstance) ,removeStateByStateName(String stateName), addEffects(BaseEffect effectInstance), addEffect(EffectCallback callback, {@required String key}), removeEffectsByKey(String key)
Implementation
Store createStore(
{List<BaseState> states,
List<BaseEffect> effects = const [],
bool enableGlobalApi = false}) {
assert(states != null && states.length > 0
? true
: throw 'states should not be null or empty.');
var store = Store(states);
effects.forEach((effect) {
store.addEffects(effect);
});
if (enableGlobalApi) {
_store = store;
}
return store;
}