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

Update for lodash v4. compatibility #308

Merged
merged 2 commits into from
Sep 13, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions backbone.stickit.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@

// Support passing a bindings hash in place of bindingSelector.
if (_.isObject(bindingSelector)) {
_.each(bindingSelector, function(v, selector) {
_.each(bindingSelector, _.bind(function(v, selector) {
this.unstickit(model, selector);
}, this);
}, this));
return;
}

Expand All @@ -71,10 +71,12 @@
});

// Trigger an event for each model that was unbound.
_.invoke(_.uniq(models), 'trigger', 'stickit:unstuck', this.cid);
_.each(_.uniq(models), _.bind(function (model) {
model.trigger('stickit:unstuck', this.cid);
}, this));

// Call `_destroy` on a unique list of the binding callbacks.
_.each(_.uniq(destroyFns), function(fn) { fn.call(this); }, this);
_.each(_.uniq(destroyFns), _.bind(function(fn) { fn.call(this); }, this));
Copy link
Contributor

Choose a reason for hiding this comment

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

how about just bind here, since that's what this function is doing anyway?


this.$el.off('.stickit' + (model ? '.' + model.cid : ''), bindingSelector);
},
Expand Down Expand Up @@ -116,9 +118,9 @@
// Support jQuery-style {key: val} event maps.
if (_.isObject(selector)) {
var bindings = selector;
_.each(bindings, function(val, key) {
_.each(bindings, _.bind(function(val, key) {
this.addBinding(model, key, val);
}, this);
}, this));
return;
}

Expand Down Expand Up @@ -167,7 +169,7 @@

if (modelAttr) {
// Setup one-way (input element -> model) bindings.
_.each(config.events, function(type) {
_.each(config.events, _.bind(function(type) {
var eventName = type + namespace;
var listener = function(event) {
var val = applyViewFn.call(this, config.getVal, $el, event, config, slice.call(arguments, 1));
Expand All @@ -178,7 +180,7 @@
};
var sel = selector === ':el'? '' : selector;
this.$el.on(eventName, sel, _.bind(listener, this));
}, this);
}, this));

// Setup a `change:modelAttr` observer to keep the view element in sync.
// `modelAttr` may be an array of attributes or a single string value.
Expand Down Expand Up @@ -332,7 +334,7 @@
var lastClass = '';
var observed = attrConfig.observe || (attrConfig.observe = modelAttr);
var updateAttr = function() {
var updateType = _.contains(props, attrConfig.name) ? 'prop' : 'attr',
var updateType = _.includes(props, attrConfig.name) ? 'prop' : 'attr',
val = getAttr(model, observed, attrConfig);

// If it is a class then we need to remove the last value and add the new.
Expand Down