Compare commits

...

2 Commits

Author SHA1 Message Date
b1fc60fc2e 1.0.14 2019-09-25 17:09:36 +02:00
8d296cf08d fix(core): update 2019-09-25 17:09:35 +02:00
4 changed files with 14 additions and 6 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartstate",
"version": "1.0.13",
"version": "1.0.14",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartstate",
"version": "1.0.13",
"version": "1.0.14",
"private": false,
"description": "a package that handles state in a good way",
"main": "dist/index.js",

View File

@ -36,14 +36,21 @@ tap.test('should select something', async () => {
});
});
tap.test('should dispatch a state action', async () => {
tap.test('should dispatch a state action', async (tools) => {
const done = tools.defer();
const addFavourite = testStatePart.createAction<string>(async (statePart, payload) => {
const currentState = statePart.getState();
currentState.currentFavorites.push(payload);
return currentState;
});
testStatePart.waitUntilPresent(state => {
return state.currentFavorites[0];
}).then(() => {
done.resolve();
});
await testStatePart.dispatchAction(addFavourite, 'my favourite things');
expect(testStatePart.getState().currentFavorites).to.include('my favourite things');
await done.promise;
});
tap.start();

View File

@ -83,12 +83,13 @@ export class StatePart<TStatePartName, TStatePayload> {
public async waitUntilPresent<T = TStatePayload>(selectorFn?: (state: TStatePayload) => T): Promise<T> {
const done = plugins.smartpromise.defer<T>();
const selectedObservable = this.select(selectorFn);
const subscription = selectedObservable.subscribe(value => {
const subscription = selectedObservable.subscribe(async value => {
if (value) {
subscription.unsubscribe();
done.resolve(value);
}
});
return await done.promise;
const result = await done.promise;
subscription.unsubscribe();
return result;
}
}