-
Notifications
You must be signed in to change notification settings - Fork 59
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
Rename willRender to willUpdate since it's related to shouldUpdate and move implementation to renderer #285
Conversation
ceeb7df
to
ff9fcc9
Compare
Just noticed this has merge conflicts. I'll rebase. |
hey @Robert-Frampton, I'm finishing the review, hold on if you wish so you can do all at once! |
…d move implementation to renderer
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.
Hey @Robert-Frampton, looks good to me in general, just some minor remarks and the rebase and we should be ready to go! 👍
@@ -28,12 +28,21 @@ import { EventEmitter, EventHandler } from 'metal-events'; | |||
* created() { | |||
* } | |||
* | |||
* willRender() { |
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.
Should this be willUpdate
?
/** | ||
* Lifecycle. Fires before component is detached from the DOM. | ||
*/ | ||
willDetach() {} |
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.
Should we also have an empty placeholder for willUpdate
? I see we are actually checking down the line to see if component.willUpdate
exists, but it feels a bit inconsistent with how we are treating every other lifecycle method.
The most similar case seems to be rendered
, which is actually always used from the component
instance informRendered
wrapper method...
@@ -94,6 +94,29 @@ describe('Component', function() { | |||
assert.ok(comp.inDocument); | |||
}); | |||
|
|||
it('should run "willAttach" lifecycle method when the component about to attach', function() { |
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.
Missing verb? when the component **is** about to attach
?
assert.strictEqual(1, comp.willAttach.callCount); | ||
}); | ||
|
||
it('should emit "willAttach" lifecycle method when the component about to attach', function() { |
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 we saying emit ... method
in the rest of tests? maybe better to say emit ... lifecycle **event** when the component **is** about to...
?
@@ -142,6 +165,37 @@ describe('Component', function() { | |||
assert.strictEqual(comp, comp.attach()); | |||
}); | |||
|
|||
it('should run "willDetach" lifecycle method when the component about to detach', function() { |
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.
Missing verb? when the component is about to detach?
assert.strictEqual(1, comp.willDetach.callCount); | ||
}); | ||
|
||
it('should emit "willDetach" lifecycle method when the component about to detach', function() { |
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 we saying emit ... method in the rest of tests? maybe better to say emit ... lifecycle event when the component is about to...?
* @param {Object} changes | ||
*/ | ||
willUpdate_(component, changes) { | ||
if (!component.willUpdate || !component.wasRendered || !changes) { |
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.
See comment above... if we want to follow the render
approach, we could provide a wrapping API for it like component.informWillUpdate
. I'm fine keeping it here too :)
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.
Also, from the calling code, it might not be needed to check for !changes
, since it is always invoked within something that used shouldUpdate(..., changes)
which already does that check?
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.
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.
Yup, we probably should! 👍
*/ | ||
handleStateWillChange_(event) { | ||
if (event.type !== 'state' && this.willReceiveProps) { | ||
this.willReceiveProps(event.changes); |
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.
This is only for JSX, right? We still should document it somehow in the docs, as we do for the other lifecycle methods. I know we are likely updating the site docs with this, but it is fairly easy to miss on code inspection.
Also, same remarks as willUpdate
about providing a default empty placeholder.
@@ -304,6 +304,8 @@ class State extends EventEmitter { | |||
*/ | |||
emitBatchEvent_() { | |||
if (!this.isDisposed()) { | |||
this.context_.emit('stateWillChange', this.scheduledBatchData_); |
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.
Not related to this change in particular, but I'm wondering how can we document what events are emitted so one knows what to listen :)
ff9fcc9
to
8ae43fb
Compare
Hey @jbalsas I made most of the changes you mentioned. I decided against adding an This is because it would be the only lifecycle method that needs to return a value, it just felt weird doing this... informShouldUpdate(...args) {
return this.shouldUpdate(...args);
}
shouldUpdate() {
return true;
} None of the other We can still do it if you think this discrepancy is fine. Edit: I should also note that if we add a placeholder that we'll have to change this logic in the Soy component. |
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.
Hey @Robert-Frampton, looks good, just 2 final issues, (sorry for the nit-picking) and we're good to go!
No need to get crazy about the forceUpdate
placeholder, let's see how this works and we can iterate later.
@@ -27,13 +27,32 @@ import { EventEmitter, EventHandler } from 'metal-events'; | |||
* class CustomComponent extends Component { | |||
* created() { | |||
* } | |||
* | |||
|
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.
Unintended deletion?
* willReceiveState() { | ||
* } | ||
* | ||
* // JSX components only |
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.
This comment here is a bit confusing... for a while I assumed everything below this point was related to JSX components only and not just this method... maybe place the comment inside? or make it more explicit, like willReceiveProps is only available in JSX components
?
Sorry, what exactly do you mean in regards to a Edit: oh, I'm guessing you meant |
…aceholder for `shouldUpdate` as some renderers need to check if it exists)
Sorry, I meant |
8ae43fb
to
7937ce6
Compare
Updated. |
No description provided.