-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Added model.when #3135
base: master
Are you sure you want to change the base?
Added model.when #3135
Conversation
Style things aside, a couple of questions — Do you think this needs to support depending on properties from just one model, or would supporting different properties from multiple models be more useful? You're adding listeners, but not removing them. Don't you need a structured way to remove/destroy the "when", when you're done with it? |
Hi Jeremy, Great questions! I'm curious also about what the style issues are, I'd be It would be interesting to be able to combine properties from multiple var a = new Backbone.Model(), a.when(['foo', 'bar'], function (foo, bar) { a.set('baz', foo + bar); }); One way to support this in the API would be like this: when([ I'm not sure how useful this would be, but I think it would be There is definitely a need to remove the listeners. I have some ideas for var model = new Backbone.Model(), Best regards, On Thu, Apr 24, 2014 at 11:49 AM, Jeremy Ashkenas
|
Just my unsolicited 2c: We added identical functionality to Backbone models around a year ago. It's been helpful in some situations, but in general I've been moving away from 'when' because it encourages inline callbacks to be mixed with regular sequential code, and (in my mind) that leads to increased cognitive load. I personally like reading functions that assume all dependent attributes are present. I.E function f(a, b) {
if (a.get('attr') === 42) {
...
} else if (b.get('attr') === 47) {
...
}
} vs. function f(a, b) {
a.when(['attr'], function(attr) {
if (attr === 42) { ... }
})
b.when(['attr'], function(attr) {
if (attr === 47) { ... }
}) Functions peppered |
@hoisie I was not aware this functionality was already added, is it still there or has it been removed? The point of this new I have made a few updates to the code:
Please let me know if there are any other issues that need to be addressed. |
Oops, I meant we extended Backbone models to add this functionality in a private repo. This feature has never been in the main Backbone repo. Your use case sounds interesting and I can see why you'd prefer using a construct like |
Added model.when for functional reactive models. See also https://github.com/curran/model .