-
Notifications
You must be signed in to change notification settings - Fork 781
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow the use of Promise that resolve to a state #305
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,8 +81,16 @@ export function app(app) { | |
}).data | ||
) | ||
|
||
if (result != null && result.then == null) { | ||
repaint((state = merge(state, emit("update", result)))) | ||
function update(data) { | ||
if (data != null) { | ||
repaint((state = merge(state, emit("update", data)))) | ||
} | ||
} | ||
|
||
if (result != null && typeof result.then == "function") { | ||
result.then(update) | ||
} else { | ||
update(result) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's change this block to: if (result != null && typeof result.then === "function") {
result.then(update)
} else {
update(result)
} and move the Rewrite it like this please. function update(withState) {
if (withState != null) {
repaint((state = merge(state, emit("update", withState))))
}
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to the slack discussion, we move from
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Swizz That's probably a misunderstanding. If There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we forbid the use of app({
state: {
foo: 0,
bar: 1,
then: 2
},
actions: {
change: state => ({ then: state.then + 1 }),
}
}) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we can forbid it. I am not too worried about this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, we need to check if If the end user return a function let execute it, and the result not null check will do the rest. If this is not a function lets do a regular result patch. Without that, using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand what you are saying, but yes, use: if (result != null && typeof result.then === "function") { There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I use the following app app({
state: {
foo: 0,
bar: 1,
then: 2
},
actions: {
change: state => ({ then: state.then + 1 }),
}
}) This will raise an error when using action
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if (result != null && typeof result.then === "function") { There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes yes 👍 |
||
|
||
return result | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we make this
else if (result != null)
and then remove theif (result == null)
above?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see, I think you were discussing a smaller impl above. Disregard.