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

[FEATURE] override attribute bindings #10213

Merged
merged 1 commit into from
Feb 6, 2015
Merged

[FEATURE] override attribute bindings #10213

merged 1 commit into from
Feb 6, 2015

Conversation

miguelcobain
Copy link
Contributor

Adds attribute binding override support.
Related with #10176.

Is there something missing? This is my first contribution attempt. :)

Maybe we should do something similar for classNameBindings.
I could make this override behaviour more abstract, but that would require to loop the attribute array again.
This way we only loop it once.

Should I wrap this behing a feature flag?

var split = binding.split(':');
var property = split[0];
var attributeName = split[1] || property;

Ember.assert('You cannot use class as an attributeBinding, use classNameBindings instead.', attributeName !== 'class');

if (property in this) {
this._setupAttributeBindingObservation(property, attributeName);
if (!attributeHash.hasOwnProperty(attributeName)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I only test this if Ember.FEATURES.isEnabled("feature-name") is true?
If so, which feature name should I use?

@miguelcobain
Copy link
Contributor Author

Just seen PR #10186.

Maybe normalizing attribute bindings externally (outside _applyAttributeBindings) would be better. (Wouldn't conflict with @mixonic work).

@miguelcobain
Copy link
Contributor Author

Idea:

Call this function (wrapped in an ember feature flag) before _applyAttributeBindings.

  _normalizeAttributeBindings: function(attributeBindings){
    var attributeHash = {};

    for (var i = attributeBindings.length-1; i >= 0; i--) {
      var binding = attributeBindings[i];
      var split = binding.split(':');
      var property = split[0];
      var attributeName = split[1] || property;

      if (!attributeHash.hasOwnProperty(attributeName)) {
        //this attribute wasn't overriden, so it's safe to process it
        //add to hash to know wether or not we processed it later
        attributeHash[attributeName] = property;
      } else {
        //overriden attribute binding, remove it
        attributeBindings.splice(i, 1);
      }
    }
  },

@miguelcobain miguelcobain changed the title don't process overriden attribute bindings [FEATURE] override attribute bindings Jan 15, 2015
@wagenet
Copy link
Member

wagenet commented Jan 21, 2015

@miguelcobain for reference, any changes to the public API should be wrapped in a feature flag.

@miguelcobain
Copy link
Contributor Author

Is this feature considered a change in the public API?
People would use attributeBindings like they always did.

@wagenet
Copy link
Member

wagenet commented Jan 21, 2015

@miguelcobain it introduces a behavior change to the API, no? (By change, I don't mean a breaking change, I just mean that it can now do something differently than it did before.)

@miguelcobain
Copy link
Contributor Author

Agreed. On it.

A qua, 21/01/2015, 22:37, Peter Wagenet [email protected] escreveu:

@miguelcobain https://github.com/miguelcobain it introduces a behavior
change to the API, no? (By change, I don't mean a breaking change, I just
mean that it can now do something differently than it did before.)


Reply to this email directly or view it on GitHub
#10213 (comment).

@miguelcobain
Copy link
Contributor Author

Well, I just added the test with no changes to the views. Tests are passing! 😕
Does this mean that this was implemented meanwhile?

@rwjblue
Copy link
Member

rwjblue commented Feb 5, 2015

@miguelcobain - The attributeBinding system was just completely replaced on master (in #10186), so it is possible that it "just works". If you squash your commits for just the tests, I'd be happy to merge this in.

@miguelcobain
Copy link
Contributor Author

@rwjblue Great! I think this is ready be merged.

rwjblue added a commit that referenced this pull request Feb 6, 2015
…dings

[FEATURE] override attribute bindings
@rwjblue rwjblue merged commit b25a7b6 into emberjs:master Feb 6, 2015
@rwjblue
Copy link
Member

rwjblue commented Feb 6, 2015

Awesome, thanks!

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.

3 participants