Skip to content
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

Merged
merged 6 commits into from
Nov 2, 2017

Conversation

robframpton
Copy link

No description provided.

@robframpton
Copy link
Author

Just noticed this has merge conflicts. I'll rebase.

@jbalsas
Copy link
Contributor

jbalsas commented Nov 1, 2017

hey @Robert-Frampton, I'm finishing the review, hold on if you wish so you can do all at once!

Copy link
Contributor

@jbalsas jbalsas left a 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() {
Copy link
Contributor

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() {}
Copy link
Contributor

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() {
Copy link
Contributor

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() {
Copy link
Contributor

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() {
Copy link
Contributor

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() {
Copy link
Contributor

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) {
Copy link
Contributor

@jbalsas jbalsas Nov 1, 2017

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 :)

Copy link
Contributor

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?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @jbalsas

In that case we might want to do the same for shouldUpdate, right now it just checks for a component.shouldUpdate method from the renderer. What do you think?

Copy link
Contributor

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);
Copy link
Contributor

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_);
Copy link
Contributor

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 :)

@robframpton
Copy link
Author

robframpton commented Nov 2, 2017

Hey @jbalsas

I made most of the changes you mentioned. I decided against adding an informShouldUpdate method and placeholder shouldUpdate method.

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 inform... methods need to return anything back to the renderer, at that point in the contract the renderer is just informing the component that something happened and doesn't care what the component does.

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.

Copy link
Contributor

@jbalsas jbalsas left a 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() {
* }
*

Copy link
Contributor

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
Copy link
Contributor

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?

@robframpton
Copy link
Author

robframpton commented Nov 2, 2017

Sorry, what exactly do you mean in regards to a forceUpdate placeholder?

Edit: oh, I'm guessing you meant shouldUpdate ;)

…aceholder for `shouldUpdate` as some renderers need to check if it exists)
@jbalsas
Copy link
Contributor

jbalsas commented Nov 2, 2017

Sorry, I meant shouldUpdate. It was related to your previous comment. Sounds good to me 👍

@robframpton
Copy link
Author

Updated.

@jbalsas jbalsas merged commit 35eb911 into metal:develop Nov 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants