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

2.0 Improvements to binding API #4510

Merged
merged 18 commits into from
Apr 13, 2017
Merged

2.0 Improvements to binding API #4510

merged 18 commits into from
Apr 13, 2017

Conversation

kevinpschaaf
Copy link
Member

  • Adds override points for _parseBindings and _evaluateBinding
  • Adds support for runtime template binding
  • Moves ready(), _hasAccessor tracking, and instance property swizzle at ready time to PropertyAccessors
  • Other refactoring and cleanup

@arthurevans
Copy link

I am so excite! And also confuse!

How can people do runtime template binding? By that do you mean identifying an instance-specific template and then calling _bindTemplate on it? (I note there's an addBinding method, but AFAICT that is private and not exposed on PropertyEffects.)

Can you bind a template more than once? (i.e., could you mutate and re-bind the template) Can you bind multiple templates?

Inquiring minds want to know...

Thanks,
Arthur

this.__dataCounter++;
this._propertiesChanged(this.__data, changedProps, oldProps);
this.__dataCounter--;
if (!this.__dataInitialized) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Now that we have __dataInitialized it probably makes sense to prevent _invalidateProperties from scheduling a flush if this flag is not true.

part.compoundIndex = i;
for (let j=0; j<dependencies.length; j++) {
let trigger = dependencies[j];
if (typeof trigger == 'string') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Bookmark to consider if we want to assume we should parseArg the trigger if it's a string.

if (hasPaths && (path.length > info.value.length) &&
(info.kind == 'property') && !info.isCompound &&
node.__propertyEffects && node.__propertyEffects[info.name]) {
if (hasPaths && part.source && (path.length > part.source.length) &&
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a comment explaining why path processing is not included with _evaluateBinding.

* @protected
*/
_stampBoundTemplate(template) {
let dom = super._stampTemplate(template);
Copy link
Contributor

Choose a reason for hiding this comment

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

super => this

}
} else {
// Property or path
dependencies.push(source);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should parseArg(source) so it doesn't auto-wildcard.

@kevinpschaaf
Copy link
Member Author

@arthurevans You can call _stampBoundTemplate(template) on a template (with bindings, events, etc.) of your choosing as many times as you like, and the doc frag returned will have elements that are bound to the element. _bindTemplate is only for prototypical binding, not runtime binding (_stampBoundTemplate stamps & binds) for more efficient stamping of the element's main template -- don't expect end users to use that unless they're building their own base classes since ElementMixin does this for you already.

_stampBoundTemplate doesn't support mutating the template and stamping it again... for that you'd just need to clone the template before mutating it, since template metadata from parsing it are memoized on the template. Should probably add that limitation to the docs. There's also a limitation with shadycss that I did mention in there, which is that since shadycss doesn't support runtime addition of <style>s, any runtime-stamped templates can't stamp new styles-- their styles need to be in the main (prototypical) template for the element.

Note one review comment is to change _stampBoundTemplate back to an override of _stampTemplate, so the name will likely change back.

This PR (and the previously merged #4432) wasn't outright intending to add new features in the RC; the main goal here was to refactor the existing code to make the whole binding system more extensible,however the ability to stamp multiple templates sort of fell out pretty easily, so we'll probably go ahead and add this feature before the final release.

Still need to add tests and address review feedback... If anything starts looking too risky we may trim this back. Will keep you in the loop.

- Adds override points for _parseBindings and _evaluateBinding
- Adds support for runtime template binding
- Moves ready(), _hasAccessor tracking, and instance property swizzle at ready time to PropertyAccessors
kevinpschaaf and others added 13 commits April 7, 2017 19:14
* PropertyAccessors must call `_flushProperties` to enable
* Avoid tearing off oldProps (unnecessary)
* Add `addBinding` docs
* Merge notifyListeners into `setupBindings`
* Add comment re: path-bindings not being overridable
* Remove `dom` argument from `_bindTemplate`
* Rename `_stampBoundTemplate` back to `_stampTemplate`
* Refactor `_bindTemplate` to remove problematic `hasCreatedAccessors`
* Remove vestigial `dom` from `_bindTemplate` call
* Rename `_unstampTemplate` to `_removeBoundDom`
* Add `infoIndex` to `nodeInfo` (and renamed parent & index)
* Add test to ensure runtime accessors created for new props in runtime stamped template
* Changed custom binding test to use different prop names
* Added test for #first count after removing bound dom
@sorvell sorvell merged commit 9997a04 into master Apr 13, 2017
@sorvell sorvell deleted the 2.0-binding-api-refactor branch April 13, 2017 23:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants