Repository navigation
Releases
Releases · patrickgwsmith/react-organism
Generator functions: animate using `yield`
- Added support for generator functions as handlers
- Each
yieldwithin a generator function may be an object of state changes, or a function that transforms the current state, or aPromiseof either - Easier animation:
window.requestAnimationFrame()is used to wait for the next frame between eachyield
Example of an animating counter’s increment, that will add 1 on every frame:
export function * increment({ stride = 20 }) {
while (stride > 0) {
yield ({ count }) => ({ count: count + 1 })
stride -= 1
}
}Example of load handler that yields initial state:
export function * load({ path }, prevProps) {
if (!prevProps || path !== prevProps.path) {
yield { items: null } // Clear so 'loading…' text appears
yield fetchAPI(path).then(items => ({ items }))
}
}