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

Availability of Views ui.hash in Behaviors is inconsistent #2339

Closed
benmccormick opened this issue Feb 17, 2015 · 4 comments
Closed

Availability of Views ui.hash in Behaviors is inconsistent #2339

benmccormick opened this issue Feb 17, 2015 · 4 comments

Comments

@benmccormick
Copy link
Contributor

From my discussion with @samccone on Gitter:

The way Behaviors mixin Views ui.hashes is inconsistent right now.

On the events and trigger hashes, Behaviors mixin view.ui to their own independent ui hash. In callback functions, only the Behavior's ui hash is available.

So this works.

let ExampleBehavior = Mn.Behavior.extend({
  events: {
    'click @ui.test' : 'doStuff'
  },

  doStuff: function() {
   //...
  }
});

let ExampleView = Mn.ItemView.extend({
  ui: {
   test: '.test'
  },
  behaviors: {
    example: {
      behaviorClass: ExampleBehavior
    }
  }

});

and this works

let ExampleBehavior = Mn.Behavior.extend({
  events: {
    'click @ui.test' : 'doStuff'
  },

  ui: {
    test: '.test'
  },

  doStuff: function() {
    this.ui.test.addClass('example');
  }
});

let ExampleView = Mn.ItemView.extend({

  behaviors: {
    example: {
      behaviorClass: ExampleBehavior
    }
  }

});

but this does not

let ExampleBehavior = Mn.Behavior.extend({
  events: {
    'click @ui.test' : 'doStuff'
  },

  doStuff: function() {
    this.ui.test.addClass('example');
  }
});

let ExampleView = Mn.ItemView.extend({
   ui: {
    test: '.test'
  },
  behaviors: {
    example: {
      behaviorClass: ExampleBehavior
    }
  }

});

It would be great to make this behavior more consistent, and either mix in view.ui consistently, or ignore it entirely.

Related to #2338

@samccone
Copy link
Member

👍

the only thing... I dislike about the coupling is that ideally behaviors should be "dumb" and not know about your views too much... this encourages coupling but.. I suppose we are already quite far down that hole

@benmccormick
Copy link
Contributor Author

I see this as making them less knowledgeable about views because they don't have to know the selectors/structure of the view (which is needed if you're going to use selectors in a separate behavior hash). It does mean views need to know more about the behaviors, but I'd rather have the views knowing about the behaviors than vice-versa.

@samccone
Copy link
Member

yep i'm with you :)

@ahumphreys87
Copy link
Member

Fixed in 2.4 via #2344

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

No branches or pull requests

3 participants