diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c8ab23..f051277 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,7 @@ #Changelog +##0.0.9 +- Bug fix for `patchGetters` where it was not late bound. + ##0.0.8 - Added a swtich to patch deep accessor (like in Backbone-Associations `.get('attr.0.name')`) in the Stickit behavior. It is off by default but you can enable it by requiring the behavior and do `StickitBehavior.patchGetters = true`; diff --git a/bower.json b/bower.json index 4dc70a2..c5ad4d3 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "marionette.behaviors", - "version": "0.0.8", + "version": "0.0.9", "authors": [ "Marc-Antoine Lemieux " ], diff --git a/lib/behaviors/stickit-behavior.js b/lib/behaviors/stickit-behavior.js index 4428512..82c6d1b 100644 --- a/lib/behaviors/stickit-behavior.js +++ b/lib/behaviors/stickit-behavior.js @@ -19,32 +19,23 @@ var StickitBehavior = Marionette.Behavior.extend({ _patchGetters: function () { - - var getValue = _.bind(function (key) { - return this.view.model.get(key); - }, this); - _.each(this.options, _.bind(function (options, key) { if (!_.isString(options) && !options.observe) return; - var value; - if (_.isString(options)) { - value = getValue(options); options = { observe: options }; - } else if (_.isArray(options.observe)) { - value = _.map(options.observe, getValue); - } else if (_.isString(options.observe)) { - value = getValue(options.observe); } - var onGet = _.isFunction(options.onGet) ? options.onGet : _.constant(value); + options.onGet = _.wrap(options.onGet, function(onGet, value, options) { + var getValue = this.model.get.bind(this.model); + var correctValue = _.isArray(options.observe) + ? _.map(options.observe, getValue) + : getValue(options.observe); - options.onGet = _.wrap(onGet, _.bind(function (func, val, opts) { - return func.call(this, value, opts); - }, this)); + return onGet ? onGet.call(this, value, options) : correctValue; + }); this.options[key] = options; }, this)); diff --git a/package.json b/package.json index 9faac36..617f21c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "marionette.behaviors", - "version": "0.0.8", + "version": "0.0.9", "description": "Collection of behaviors for Marionette", "main": "index.js", "scripts": {