Skip to content

Commit

Permalink
Optimized Instance to a small degree
Browse files Browse the repository at this point in the history
  • Loading branch information
notheotherben committed Apr 29, 2015
1 parent d2a9d75 commit 26d94e0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/Instance.js

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

2 changes: 1 addition & 1 deletion lib/Instance.js.map

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

10 changes: 5 additions & 5 deletions lib/Instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Instance<TDocument extends { _id?: any }, TInstance> {
this._isNew = !!isNew;
this._isPartial = isPartial;
this._original = document;
this._modified = _.cloneDeep(document);
this._modified = _.cloneDeep<TDocument>(document);

_.each(model.core.plugins,(plugin: IPlugin) => {
if (plugin.newInstance) plugin.newInstance(this, model);
Expand Down Expand Up @@ -134,7 +134,7 @@ class Instance<TDocument extends { _id?: any }, TInstance> {
this._isPartial = false;
this._isNew = false;
this._original = value;
this._modified = _.clone(value);
this._modified = _.clone<TDocument>(value);
return <TInstance><any>this;
});
}).nodeify(callback);
Expand Down Expand Up @@ -168,15 +168,15 @@ class Instance<TDocument extends { _id?: any }, TInstance> {
if (!newDocument) {
this._isPartial = true;
this._isNew = true;
this._original = _.cloneDeep(this._modified);
this._original = _.cloneDeep<TDocument>(this._modified);
return <Bluebird<TInstance>><any>this;
}

return this._model.handlers.documentReceived<TDocument>(conditions, newDocument, doc => doc).then((doc) => {
return this._model.handlers.documentReceived(conditions, newDocument, (doc) => {
this._isNew = false;
this._isPartial = false;
this._original = doc;
this._modified = _.cloneDeep(doc);
this._modified = _.cloneDeep<TDocument>(doc);

return <TInstance><any>this;
});
Expand Down

0 comments on commit 26d94e0

Please sign in to comment.