-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Implement support for the amp-bind premutate message #12906
Conversation
src/service/viewer-impl.js
Outdated
this.messageObservables_[eventType] = observable; | ||
} | ||
return observable.add(handler); | ||
this.messageHandlers_[eventType] = handler; |
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.
Does this mean that a given eventType can only have one handler? Not sure that's desirable or safe -- let's retain the current behavior if possible.
How about adding an optional parameter to Observable#fire
such that it returns Promise.all(<invoked_handlers>)
if provided?
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.
I don't think that would work because then the promise would return an array, and that's not what we want to send in the response. I updated this code now to keep the onMessage
method as is, and add a separate onMessageRespond
method that makes the provided function the sole handler that responds to the message. So any given message type can have one responder, but multiple other observers.
extensions/amp-bind/0.1/bind-impl.js
Outdated
/** | ||
* @param {string} eventType | ||
* @param {*} data | ||
* @private |
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.
@return {!Promise}
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.
Done
extensions/amp-bind/0.1/bind-impl.js
Outdated
premutate_(eventType, data) { | ||
const ignoredKeys = []; | ||
return this.initializePromise_ | ||
.then(() => { |
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.
Nit: This can fit on the previous line.
@@ -333,6 +337,39 @@ export class Bind { | |||
return this.history_; | |||
} | |||
|
|||
/** |
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.
"Calls setState(s), where s is data.state with non-overridable keys removed."
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.
Done
/cc @honeybadgerdontcare Validator change FYI. |
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.
validation changes look good
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, are you planning to return error info from premutate_
? I assume this will be in the next PR?
extensions/amp-bind/0.1/bind-impl.js
Outdated
* @return {!Promise} | ||
* @private | ||
*/ | ||
premutate_(eventType, data) { |
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.
Are you planning to use awaitResponse
?
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.
No, I didn't end up using it. I removed eventType
and awaitResponse
from the function signature for the handlers now.
@choumx I'm not planning on returning error info (I assume you mean non-overridable keys?) from premutate_. I thought we decided in the design review not to do that, and to just log them here instead. If we decide to do it, I can do it in a follow up PR. |
Just asking because I wondered why |
I guess you're right that would have possibly worked in this case, although I think it probably would have returned an an array with just one |
Obviously, feel free to merge if you think it's ready. I'm not able to. |
Thanks for contributing this! |
* Implement support for the amp-bind premutate message * fix unit tests * Fix lint * Revert changes to onMessage and instead add a new onMessageRespond method * remove eventType and awaitResponse from RequestResponder parameters
* Revision bump for ampproject#12862 * Revision bump for ampproject#13001 * Revision bump for ampproject#12906
* Implement support for the amp-bind premutate message * fix unit tests * Fix lint * Revert changes to onMessage and instead add a new onMessageRespond method * remove eventType and awaitResponse from RequestResponder parameters
* Revision bump for ampproject#12862 * Revision bump for ampproject#13001 * Revision bump for ampproject#12906
* Revision bump for ampproject#12862 * Revision bump for ampproject#13001 * Revision bump for ampproject#12906
Closes #12811
@choumx