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

Port attributeBindings to AttrNode views #10186

Merged
merged 1 commit into from
Feb 5, 2015

Conversation

mixonic
Copy link
Member

@mixonic mixonic commented Jan 10, 2015

Ember's attribute bindings were a custom system based on the buffer and a view. The buffer would be updated with initial values, and the element have those attributes applied during it's own render pass. Observers were attached to watch changing values.

This refactors attribute bindings to use AttrNode objects, which in turn are rendered like a normal view on the renderer. They have access to morphs and the domHelper in a standard view-ish way.

TODO

/cc @mmun @krisselden and view-layer crew.

Closes #9921

@@ -553,7 +553,6 @@ test('should not reset cursor position when text field receives keyUp event', fu

appendView(view);

view.$().val('Brosiedoon, King of the Brocean');
Copy link
Member Author

Choose a reason for hiding this comment

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

The old logic for writing a value would compare the value to be set against the one currently in the DOM.

In the new logic, a cached last value is compared instead. The bound attribute does not want a 3rd party (here, a jQuery call) to change the properties.

We may need to fall back to the check-dom-every-time strategy if this is problematic.

Copy link
Member

Choose a reason for hiding this comment

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

I much prefer the new logic of caching the last value. IMHO, it has been fairly clear thst third parties changing the DOM underneath is not acceptable. It may have worked in this particular instance, but many many others did not.

@rwjblue
Copy link
Member

rwjblue commented Jan 11, 2015

This looks wonderful!

@rwjblue
Copy link
Member

rwjblue commented Jan 12, 2015

HTMLBars v0.8.1 includes the upstream HTMLBars changes needed for this.

@mixonic mixonic force-pushed the attribute-bindings branch 2 times, most recently from cebe456 to c32d9c3 Compare January 12, 2015 01:19
@rwjblue
Copy link
Member

rwjblue commented Jan 12, 2015

I believe that this should close #9921, @mixonic if you agree can you update the description?

@mixonic mixonic force-pushed the attribute-bindings branch 2 times, most recently from 09b7fc5 to d06d108 Compare January 12, 2015 02:42
binding = attributeBindings[i];
split = binding.split(':');
property = split[0];
attrName = split[1] || property;
Copy link
Contributor

Choose a reason for hiding this comment

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

attrName should be the full name in case of namespaced attributes, rather than split[1]. I believe that would take care of #9298.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oof this is for micro-syntax not for namespaced attrs. The solution is not as super-simple as it seems, imo.

  • isDisabled:disabled is a mapping of view-prop:attr
  • xlink:href is a namespaced attr
  • hrefLink:xlink:href is a mapping of view-prop:namespaced-attr

There isn't really a way to support all that. I would propose:

  • isDisabled:disabled is a mapping of view-prop:attr
  • xlink:href is a mapping of view-prop:attr (gotcha)
  • hrefLink:xlink:href is a mapping of view-prop:namespaced-attr

This would be consistent. Basically, the micro-syntax sucks. Maybe we can drop it in 2.0. I don't want to tackle it here though.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good thinking! Since : isn't valid a valid character for property names, they'd have to use a view-prop anyway, right? In that case the gotcha's not much of a limitation, since there's no way they could define the property for xlink:href under its own name even if they wanted to. (If I remember the whole mapping thing right, that is)

@mixonic
Copy link
Member Author

mixonic commented Jan 12, 2015

Opened an upstream PR at tildeio/htmlbars#253, and an issue at tildeio/htmlbars#251 that needs a PR.

IE10 is a go, still have two or three IE9 issues.

@mixonic
Copy link
Member Author

mixonic commented Jan 14, 2015

IE9 is a go. PR opened for tildeio/htmlbars#256.

I need to wait on IE8 until HTMLBars is working again.

@mixonic
Copy link
Member Author

mixonic commented Jan 18, 2015

Getting close. IE9 and up are 100% with htmlbars master. Just IE8.

@rwjblue
Copy link
Member

rwjblue commented Jan 25, 2015

I'm comfortable landing this for current master (which will branch to 1.11 shortly), but I think @mixonic is waiting to review and confirm that this general strategy will work for IE8.

@rwjblue
Copy link
Member

rwjblue commented Jan 26, 2015

ping @mixonic - have any updates here?

@mixonic mixonic force-pushed the attribute-bindings branch 2 times, most recently from e27cafb to a4d4a90 Compare January 30, 2015 05:01
@mixonic
Copy link
Member Author

mixonic commented Jan 30, 2015

Rebased this tonight.

Something in IE8 on master causes the page to crash then reload. I'm blocked on that now.

Unless someone else wants to hop on it first, some IE things we should do before trying to fix 8:

  • Most of the test changes here are IE fixes for master. They can be pulled into a new PR for master.
  • Many of them can likely land in beta as well.
  • First the reload issues in IE8 needs to be addressed. I want to suggest it has something to do with sanitization, but I'm very unsure at this point.
  • Then IE8 in general needs to be confirmed as working.
  • Then I can get the IE8 fixes for this patch done.

I'll be working on some of this over the weekend.

@mixonic
Copy link
Member Author

mixonic commented Feb 1, 2015

Needs tildeio/htmlbars#276 to land for node tests to pass

@mixonic mixonic force-pushed the attribute-bindings branch 3 times, most recently from cbdf7fc to 04ce7a1 Compare February 5, 2015 04:39
@mixonic
Copy link
Member Author

mixonic commented Feb 5, 2015

This is good implementation-wise. Performance benchmarks stand unchanged against master itself (tested with render list, render list with link-to, and render link-to).

I believe this is good to go.

@mixonic
Copy link
Member Author

mixonic commented Feb 5, 2015

I swear this is a net lines-of-code win, just need to wait until we strip the ember-htmlbars-attribute-syntax feature flag. Re-using this pattern for classNameBindings will also help.

rwjblue added a commit that referenced this pull request Feb 5, 2015
Port attributeBindings to AttrNode views
@rwjblue rwjblue merged commit 0e0046a into emberjs:master Feb 5, 2015
@rwjblue rwjblue deleted the attribute-bindings branch February 5, 2015 15:31
@oneeman
Copy link
Contributor

oneeman commented Feb 5, 2015

Awesome! Since this is merged now, I could do a PR to implement #10186 (comment).

@mixonic
Copy link
Member Author

mixonic commented Feb 6, 2015

Turns out this definitely breaks container view. But also there are no tests in all of Ember that use attribute bindings and container view so meeeeh.

Working on the classNameBindings patch this weekend, and will make part of that porting the attr nodes onto _attrViews or something not the _childViews array. I believe that is the best way out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Port applyAttributeBindings to attr nodes
4 participants