|
|
|
@ -37,7 +37,7 @@ export class StatePart<TStatePartName, TStatePayload> {
|
|
|
|
|
if (
|
|
|
|
|
this.stateStore &&
|
|
|
|
|
this.lastStateNotificationPayloadHash &&
|
|
|
|
|
createStateHash(this.stateStore) === createStateHash(this.lastStateNotificationPayloadHash)
|
|
|
|
|
createStateHash(this.stateStore) === this.lastStateNotificationPayloadHash
|
|
|
|
|
) {
|
|
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
@ -47,6 +47,14 @@ export class StatePart<TStatePartName, TStatePayload> {
|
|
|
|
|
}
|
|
|
|
|
private lastStateNotificationPayloadHash: any;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* creates a cumulative notification by adding a change notification at the end of the call stack;
|
|
|
|
|
*/
|
|
|
|
|
public notifyChangeCumulative() {
|
|
|
|
|
// TODO: check viability
|
|
|
|
|
setTimeout(() => this.state.next(this.stateStore), 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* selects a state or a substate
|
|
|
|
|
*/
|
|
|
|
@ -56,7 +64,6 @@ export class StatePart<TStatePartName, TStatePayload> {
|
|
|
|
|
if (!selectorFn) {
|
|
|
|
|
selectorFn = (state: TStatePayload) => <T>(<any>state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapped = this.state.pipe(
|
|
|
|
|
plugins.smartrx.rxjs.ops.startWith(this.getState()),
|
|
|
|
|
plugins.smartrx.rxjs.ops.map((stateArg) => {
|
|
|
|
@ -67,7 +74,6 @@ export class StatePart<TStatePartName, TStatePayload> {
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return mapped;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -111,9 +117,11 @@ export class StatePart<TStatePartName, TStatePayload> {
|
|
|
|
|
/**
|
|
|
|
|
* is executed
|
|
|
|
|
*/
|
|
|
|
|
public stateSetup(
|
|
|
|
|
funcArg: (statePartArg?: StatePart<any, TStatePayload>) => Promise<TStatePayload | void>
|
|
|
|
|
public async stateSetup(
|
|
|
|
|
funcArg: (statePartArg?: StatePart<any, TStatePayload>) => Promise<TStatePayload>
|
|
|
|
|
) {
|
|
|
|
|
this.cumulativeDeferred.addPromise(funcArg(this));
|
|
|
|
|
const resultPromise = funcArg(this);
|
|
|
|
|
this.cumulativeDeferred.addPromise(resultPromise);
|
|
|
|
|
this.setState(await resultPromise);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|