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

Bump to version 0.10.5 #80

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,22 @@ Example code:
{ name: 'Cyrril' }
]
});

//You can bind to change events on nested attributes
model.bind('change:user.name.first', function(model, val) {
console.log(val);
});

//Wildcards are supported
model.bind('change:user.*', function() {});

//Use set with a path name for nested attributes
//NOTE you must you quotation marks around the key name when using a path
model.set({
'user.name.first': 'Lana',
'user.name.last': 'Kang'
});

//Use get() with path names so you can create getters later
console.log(model.get('user.type')); // 'Spy'

Expand All @@ -78,6 +78,9 @@ Contributors
Changelog
=========

0.10.5:
- Trigger change events only once and trigger change event for parent keys (like wildcard)

0.10.4:
- Fix #68 Model or collection in attributes are eliminated when defaults are used

Expand Down
32 changes: 23 additions & 9 deletions distribution/deep-model.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*jshint expr:true eqnull:true */
/**
*
* Backbone.DeepModel v0.10.4
* Backbone.DeepModel v0.10.5
*
* Copyright (c) 2013 Charles Davison, Pow Media Ltd
*
Expand Down Expand Up @@ -132,7 +132,7 @@
factory(_, Backbone);
}
}(function(_, Backbone) {

/**
* Takes a nested object and returns a shallow object keyed with the path names
* e.g. { "level1.level2": "value" }
Expand Down Expand Up @@ -184,7 +184,7 @@
if (result == null && i < n - 1) {
result = {};
}

if (typeof result === 'undefined') {
if (return_exists)
{
Expand Down Expand Up @@ -274,7 +274,7 @@
set: function(key, val, options) {
var attr, attrs, unset, changes, silent, changing, prev, current;
if (key == null) return this;

// Handle both `"key", value` and `{key: value}` -style arguments.
if (typeof key === 'object') {
attrs = key;
Expand All @@ -284,7 +284,7 @@
}

options || (options = {});

// Run validation.
if (!this._validate(attrs, options)) return false;

Expand Down Expand Up @@ -329,11 +329,15 @@

//<custom code>
var separator = DeepModel.keyPathSeparator;
var alreadyTriggered = {}; // * @restorer

for (var i = 0, l = changes.length; i < l; i++) {
var key = changes[i];

this.trigger('change:' + key, this, getNested(current, key), options);
if (!alreadyTriggered.hasOwnProperty(key) || !alreadyTriggered[key]) { // * @restorer
alreadyTriggered[key] = true; // * @restorer
this.trigger('change:' + key, this, getNested(current, key), options);
} // * @restorer

var fields = key.split(separator);

Expand All @@ -342,7 +346,17 @@
var parentKey = _.first(fields, n).join(separator),
wildcardKey = parentKey + separator + '*';

this.trigger('change:' + wildcardKey, this, getNested(current, parentKey), options);
if (!alreadyTriggered.hasOwnProperty(wildcardKey) || !alreadyTriggered[wildcardKey]) { // * @restorer
alreadyTriggered[wildcardKey] = true; // * @restorer
this.trigger('change:' + wildcardKey, this, getNested(current, parentKey), options);
} // * @restorer

// + @restorer
if (!alreadyTriggered.hasOwnProperty(parentKey) || !alreadyTriggered[parentKey]) {
alreadyTriggered[parentKey] = true;
this.trigger('change:' + parentKey, this, getNested(current, parentKey), options);
}
// - @restorer
}
//</custom code>
}
Expand Down Expand Up @@ -388,7 +402,7 @@
//</custom code>

var old = this._changing ? this._previousAttributes : this.attributes;

//<custom code>
diff = objToPaths(diff);
old = objToPaths(old);
Expand Down Expand Up @@ -431,7 +445,7 @@

//For use in NodeJS
if (typeof module != 'undefined') module.exports = DeepModel;

return Backbone;

}));
Expand Down
4 changes: 2 additions & 2 deletions distribution/deep-model.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"author": {
"name": "Charles Davison"
},
"version": "0.10.4",
"version": "0.10.5",
"dependencies": {
"backbone": ">=0.9.10"
},
Expand Down