Skip to content
This repository was archived by the owner on Jul 30, 2018. It is now read-only.

Ensure properties and children are 'reset' each render for a projector #501

Merged
merged 1 commit into from
May 15, 2017

Conversation

agubler
Copy link
Member

@agubler agubler commented May 11, 2017

Type: bug

The following has been addressed in the PR:

  • There is a related issue
  • All code matches the style guide
  • Unit or Functional tests are included in the PR

Description:

Ensure properties and children are reset each render back to the last received set by either setProperties or setChildren

Resolves #498

@agubler agubler requested review from matt-gadd and kitsonk May 11, 2017 15:03
@dylans dylans added this to the 2017.05 milestone May 11, 2017
@@ -215,14 +218,22 @@ export function ProjectorMixin<P, T extends Constructor<WidgetBase<P>>>(base: T)
}

public setChildren(children: DNode[]): void {
this._projectorChildren = [ ...children ];
Copy link
Member

Choose a reason for hiding this comment

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

Why wouldn't we be doing super.__setChildren__(this._projectorChildren)? Feels like a little bit of indirection. Also if we did this, wouldn't we just be able to this.setChildren(this.children) and this.setProperties(this.properties) below?

Copy link
Member Author

Choose a reason for hiding this comment

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

We are taking a copy at the point in time the user has explicitly called setProperties or setChildren, because the properties and children that are passed can be decorated in lifecycle phases such as beforeRender - on a re-render for all other widgets in the widget tree a "fresh" properties object is used via the usage of w() but for the projector that is not the case and therefore the next render the possibly modified properties are used again (which means it can cause unexpected behaviour). So with these "copied" local value we re-set the properties/children in WidgetBase by calling the setters.

We could actually directly call the supers __setProperties__ and __setChildren__ from the __render__ method as we only need the to take the copy when the user has actually called the methods intended for public consumption setProperties and setChildren - I can change that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ha nope of course I'm wrong, I do need to take the copy every time over wise my "frozen" properties/children will possibly be mutated then next time they are used to call __setProperties__ or __setChildren__. Doh.

super.__setChildren__(children);
}

public setProperties(properties: P & { [index: string]: any }): void {
this._projectorProperties = assign({}, properties);
Copy link
Member

Choose a reason for hiding this comment

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

Could also do { ...properties } now, though I guess with offloading to native, assign will always be quicker.

Copy link
Member Author

Choose a reason for hiding this comment

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

I actually prefer the spreading but you get an error Spread types may only be created from object types. I think when the type is a generic.

Copy link
Member

Choose a reason for hiding this comment

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

Hmmm... I couldn't find anything on TypeScript issues, so I opened this: microsoft/TypeScript#15792

Copy link
Member

Choose a reason for hiding this comment

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

It was a dupe... PR microsoft/TypeScript#13288 will resolve it.

@codecov
Copy link

codecov bot commented May 12, 2017

Codecov Report

Merging #501 into master will increase coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #501      +/-   ##
==========================================
+ Coverage   97.02%   97.04%   +0.02%     
==========================================
  Files          18       18              
  Lines         907      915       +8     
  Branches      140      142       +2     
==========================================
+ Hits          880      888       +8     
  Misses          3        3              
  Partials       24       24
Impacted Files Coverage Δ
src/mixins/Projector.ts 95% <100%> (+0.43%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5d3b4d7...f54126b. Read the comment docs.

@agubler agubler requested a review from tomdye May 15, 2017 09:17
@agubler agubler merged commit aaa9539 into dojo:master May 15, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants