Skip to content

Commit

Permalink
Merge pull request #143 from Kanaye/fix-#93
Browse files Browse the repository at this point in the history
Fix #93
  • Loading branch information
astoilkov committed May 26, 2016
2 parents bb5b85c + a3099ed commit dddbd0a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
5 changes: 5 additions & 0 deletions lib/blocks/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
* Copies properties from all provided objects into the first object parameter
*
* @memberof blocks
* @param {boolean} [deepCopy] - If true, the merge becomes recursive (aka. deep copy)
* @param {Object} obj
* @param {...Object} objects
* @returns {Object}
Expand Down Expand Up @@ -556,6 +557,10 @@
var clone;
var key;

if (blocks.isFunction(value.clone)) {
return value.clone(deepClone);
}

if (type == 'array') {
return value.slice(0);
} else if (type == 'object') {
Expand Down
6 changes: 5 additions & 1 deletion src/mvc/Application.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ define([
this._super([_this, prototype, dataItem, collection]);
};

prototype = prototype || {};
prototype = blocks.clone(prototype, true) || {};
prototype.options = prototype.options || {};

return blocks.inherit(Model, ExtendedModel, prototype);
Expand Down Expand Up @@ -475,6 +475,10 @@ define([
this.View.Defaults = blocks.observable({
options: { }
}).extend();
},
// Application is a singleton. So return a reference instead of a clone.
clone: function () {
return this;
}
};
});
18 changes: 13 additions & 5 deletions src/mvc/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ define([
*/
function Model(application, prototype, dataItem, collection) {
var _this = this;
// deep clone dataItem, otherwise we don't clone obervables nested in Models
dataItem = blocks.clone(dataItem, true);
this._application = application;
this._prototype = prototype;
this._collection = collection;
this._initialDataItem = blocks.clone(dataItem, true);

Expand Down Expand Up @@ -271,17 +274,22 @@ define([
},

clone: function () {
return new this.constructor(blocks.clone(this._initialDataItem, true));
var self = this;
var data = {};
blocks.each(this._prototype, function (val, key) {
data[key] = blocks.clone(self[key], true);
});
return new this.constructor(data);
},

_setPropertyValue: function (property, propertyValue) {
var propertyName = property.propertyName;
if (blocks.isFunction(this[propertyName])) {
if (property.isObservable) {
this[propertyName] = this._createObservable(property, propertyValue);
} else if (blocks.isFunction(this[propertyName])) {
this[propertyName](propertyValue);
this._dataSource.update(this.dataItem());
} else if (property.isObservable) {
this[propertyName] = this._createObservable(property, propertyValue);
} else {
} else {
this[propertyName] = function () {
return propertyValue;
};
Expand Down
4 changes: 4 additions & 0 deletions src/mvc/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ define([

_error: function () {
this.loading(false);
},
// View is a singleton so return a reference
clone: function () {
return this;
}
};

Expand Down

0 comments on commit dddbd0a

Please sign in to comment.