-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Labels
Description
const Clock = provideState({
computed: {
// it simply returns an async iterator instead of a value
//
// the computed is undefined before the first
// value is emitted by the iterator
//
// each new emitted value will trigger a new render with the
// computed set to this value
//
// rejections are not handled and will possibly trigger an
// unhandledRejection event on the window object, the computed will
// keep its previous value
//
// this computed, which does not have dependencies, yields a new
// date value every second
async *date() {
while (true) {
yield new Date()
await new Promise(resolve => setTimeout(resolve, 1e3))
}
}
}
})(injectState(({ state }) => <p>{state.date.toISOString()}</p>))