Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
b1fc60fc2e | |||
8d296cf08d |
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartstate",
|
"name": "@pushrocks/smartstate",
|
||||||
"version": "1.0.13",
|
"version": "1.0.14",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartstate",
|
"name": "@pushrocks/smartstate",
|
||||||
"version": "1.0.13",
|
"version": "1.0.14",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "a package that handles state in a good way",
|
"description": "a package that handles state in a good way",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
@ -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 addFavourite = testStatePart.createAction<string>(async (statePart, payload) => {
|
||||||
const currentState = statePart.getState();
|
const currentState = statePart.getState();
|
||||||
currentState.currentFavorites.push(payload);
|
currentState.currentFavorites.push(payload);
|
||||||
return currentState;
|
return currentState;
|
||||||
});
|
});
|
||||||
|
testStatePart.waitUntilPresent(state => {
|
||||||
|
return state.currentFavorites[0];
|
||||||
|
}).then(() => {
|
||||||
|
done.resolve();
|
||||||
|
});
|
||||||
await testStatePart.dispatchAction(addFavourite, 'my favourite things');
|
await testStatePart.dispatchAction(addFavourite, 'my favourite things');
|
||||||
expect(testStatePart.getState().currentFavorites).to.include('my favourite things');
|
expect(testStatePart.getState().currentFavorites).to.include('my favourite things');
|
||||||
|
await done.promise;
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
|
@ -83,12 +83,13 @@ export class StatePart<TStatePartName, TStatePayload> {
|
|||||||
public async waitUntilPresent<T = TStatePayload>(selectorFn?: (state: TStatePayload) => T): Promise<T> {
|
public async waitUntilPresent<T = TStatePayload>(selectorFn?: (state: TStatePayload) => T): Promise<T> {
|
||||||
const done = plugins.smartpromise.defer<T>();
|
const done = plugins.smartpromise.defer<T>();
|
||||||
const selectedObservable = this.select(selectorFn);
|
const selectedObservable = this.select(selectorFn);
|
||||||
const subscription = selectedObservable.subscribe(value => {
|
const subscription = selectedObservable.subscribe(async value => {
|
||||||
if (value) {
|
if (value) {
|
||||||
subscription.unsubscribe();
|
|
||||||
done.resolve(value);
|
done.resolve(value);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return await done.promise;
|
const result = await done.promise;
|
||||||
|
subscription.unsubscribe();
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user