Skip to content

Commit

Permalink
fix patch getters and bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc-Antoine Lemieux committed Mar 13, 2015
1 parent 358adea commit b9eb5c6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 18 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`;

Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "marionette.behaviors",
"version": "0.0.8",
"version": "0.0.9",
"authors": [
"Marc-Antoine Lemieux <[email protected]>"
],
Expand Down
23 changes: 7 additions & 16 deletions lib/behaviors/stickit-behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit b9eb5c6

Please sign in to comment.