storeon-until
Advanced tools
Comparing version 1.0.1 to 1.0.2
# Change Log | ||
This project adheres to [Semantic Versioning](http://semver.org/). | ||
## 1.0.2 | ||
* Readme update. | ||
## 1.0.1 | ||
@@ -4,0 +8,0 @@ * Readme update. |
{ | ||
"name": "storeon-until", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Small simple utility for awaiting [Storeon] event occurs", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -43,17 +43,16 @@ # storeon-until | ||
// awaiting for the ending event | ||
const documentLoadedPromise = await until(store, 'documentLoaded', (_, {id}) => id === 'id1'); | ||
// dispatch event | ||
store.dispatch('loadDocument', 'id1'); | ||
// waits until async flow will finish | ||
const {id, document} = | ||
await until(store, 'documentLoaded', (_, {id}) => id === 'id1'); | ||
const {id, document} = await documentLoadedPromise; | ||
console.log(document); | ||
// we can also await for the state | ||
const statePromise = until(store, '@changed', ({id}) => id === 'id2'); | ||
// dispatch event | ||
store.dispatch('loadDocument', 'id2'); | ||
// waits until data in state will pass condition | ||
const {id, document} = | ||
await until(store, '@changed', ({id}) => id === 'id2'); | ||
const {id, document} = await statePromise; | ||
console.log(document); | ||
@@ -63,2 +62,7 @@ | ||
**Caution** | ||
Please notice, that we should always use `until` utility to create promise before the event dispatch | ||
as dispatched event can run synchronously. | ||
### Api | ||
@@ -65,0 +69,0 @@ - `until` - is function which returns promise of requested event data. Params: |
721744
72