Skip to content
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
17 changes: 13 additions & 4 deletions ampersand-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ function Base(attrs, options) {
this._values = {};
this._eventBubblingHandlerCache = {};
this._definition = Object.create(this._definition);
if (options.parse) attrs = this.parse(attrs, options);
this.parent = options.parent;
this.collection = options.collection;
this._keyTree = new KeyTree();
this._initCollections();
this._initChildren();
this.initializeBeforeSet(options);
this._cache = {};
this._previousAttributes = {};
if (attrs) this.set(attrs, assign({silent: true, initial: true}, options));
Expand All @@ -53,6 +53,11 @@ assign(Base.prototype, Events, {

typeAttribute: 'modelType',

// Stubbed out to be overwritten
initializeBeforeSet: function () {
return this;
},

// Stubbed out to be overwritten
initialize: function () {
return this;
Expand Down Expand Up @@ -132,6 +137,8 @@ assign(Base.prototype, Events, {

options = options || {};

if (options.parse) attrs = this.parse(attrs, options);

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

// Extract attributes and options.
Expand Down Expand Up @@ -506,11 +513,13 @@ assign(Base.prototype, Events, {
// adding a name to the change string.
_getCachedEventBubblingHandler: function (propertyName) {
if (!this._eventBubblingHandlerCache[propertyName]) {
this._eventBubblingHandlerCache[propertyName] = bind(function (name, model, newValue) {
this._eventBubblingHandlerCache[propertyName] = bind(function (name, model, newValue, options) {
if (changeRE.test(name)) {
this.trigger('change:' + propertyName + '.' + name.split(':')[1], model, newValue);
var parentName = 'change:' + propertyName + '.' + name.split(':')[1];
this.trigger(parentName, model, newValue, options);
} else if (name === 'change') {
this.trigger('change', this);
options = newValue;
this.trigger('change', this, options);
}
}, this);
}
Expand Down
Loading