fix(core): update

This commit is contained in:
2023-04-04 20:59:45 +02:00
parent 7e0dad1c10
commit fc4fb911ef
5 changed files with 1144 additions and 1591 deletions

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@pushrocks/smartstate',
version: '2.0.1',
version: '2.0.2',
description: 'a package that handles state in a good way'
}

View File

@ -5,6 +5,7 @@ export class StatePart<TStatePartName, TStatePayload> {
public name: TStatePartName;
public state = new plugins.smartrx.rxjs.Subject<TStatePayload>();
public stateStore: TStatePayload;
private cumulativeDeferred = plugins.smartpromise.cumulativeDefer();
constructor(nameArg: TStatePartName) {
this.name = nameArg;
@ -79,6 +80,7 @@ export class StatePart<TStatePartName, TStatePayload> {
* dispatches an action on the statepart level
*/
public async dispatchAction<T>(stateAction: StateAction<TStatePayload, T>, actionPayload: T) {
await this.cumulativeDeferred.promise;
const newState = await stateAction.actionDef(this, actionPayload);
this.setState(newState);
}
@ -101,4 +103,11 @@ export class StatePart<TStatePartName, TStatePayload> {
subscription.unsubscribe();
return result;
}
/**
* is executed
*/
public stateSetup(funcArg: (statePartArg?: StatePart<any, TStatePayload>) => Promise<TStatePayload | void>) {
this.cumulativeDeferred.addPromise(funcArg(this));
}
}