promises#38
Conversation
|
Yes, I already facing some problem while using |
| return; | ||
| return Promise.all(promises).then(() => { | ||
| if (callback) { | ||
| return callback(); |
There was a problem hiding this comment.
If something inside the callback function throws then the error might get swallowed.
| onUpdate: Listener = cb => { | ||
| this.setState(DUMMY_STATE, cb); | ||
| onUpdate: Listener = () => { | ||
| return new Promise(resolve => { |
There was a problem hiding this comment.
why not just return this.setState(DUMMY_STATE); (instead of creating a new promise)?
There was a problem hiding this comment.
because then we dont wait for the callback
|
@jamiebuilds I tried this in our app and it works perfectly. |
|
Why not pick one or the other? There is no need for 2 different mechanisms to notify on update, and the promise version is cleaner and easier to test. const callback = () => console.log('state updated')
// with callback
setState({
some: 'newValue',
}, callback)
// with promise
setState({
some: 'newValue',
}).then(callback)
// sooner or later, someone will do this
const promise = setState({
some: 'newValue',
}, callback)
promise.then(callback) |
|
@jamiebuilds Is there any update on this? I'd love to see this PR merged in -- it makes the |
|
@ldthorne This isn't consistent, which is fine, but is different from the behavior of React. React's API does not return a promise, it uses the callback style. React's API:
Unstated since version 2:
This PR:
|
|
@jamiebuilds can you create a new release for this on NPM? We'd love to start using this in production |
|
@jamiebuilds What about this case? |
|
@nfort fixed in 2.1.1 |
This re-implements parts of
setStateso that it returns a promise It simplifies a lot about the implementation. The only problem is that we always pass a callback to React'ssetStatewhich may be a perf issue for some apps.