bem-promised-models
Advanced tools
Comparing version 0.0.13 to 0.0.14
@@ -256,3 +256,3 @@ (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
this.storage = new Storage(); | ||
this.attributes = Object.keys(this.attributes || {}).reduce(function (attributes, name) { | ||
this.attributes = Object.keys(this.__self.attributes || {}).reduce(function (attributes, name) { | ||
var Attribute = model.attributes[name]; | ||
@@ -286,3 +286,2 @@ attributes[name] = new (Attribute.inherit({ | ||
/** | ||
@@ -294,19 +293,20 @@ * save model changes | ||
var model = this; | ||
if (model.isNew()) { | ||
return model.ready().then(function () { | ||
return model.storage.insert(model); | ||
}).then(function (id) { | ||
model.id = id; | ||
model.commit(); | ||
model.calculate().done(); | ||
return model.ready(); | ||
}); | ||
} else { | ||
return model.ready().then(function () { | ||
return model.storage.update(model); | ||
}).then(function () { | ||
model.commit(); | ||
}); | ||
} | ||
return this._rejectDestructed().then(function () { | ||
if (model.isNew()) { | ||
return model.ready().then(function () { | ||
return model.storage.insert(model); | ||
}).then(function (id) { | ||
model.id = id; | ||
model.commit(); | ||
model.calculate().done(); | ||
return model.ready(); | ||
}); | ||
} else { | ||
return model.ready().then(function () { | ||
return model.storage.update(model); | ||
}).then(function () { | ||
model.commit(); | ||
}); | ||
} | ||
}); | ||
}, | ||
@@ -439,3 +439,5 @@ | ||
Object.keys(data).forEach(function (name) { | ||
model.set(name, data[name]); | ||
if (data[name] !== undefined) { | ||
model.set(name, data[name]); | ||
} | ||
}); | ||
@@ -482,5 +484,7 @@ } else if (this.attributes[name]) { | ||
* @param {*} [ctx] | ||
* @return {Model} | ||
*/ | ||
un: function (attribute, event, cb, ctx) { | ||
this._callEventEmitter('removeListener', attribute, event, cb, ctx); | ||
return this; | ||
}, | ||
@@ -494,5 +498,7 @@ | ||
* @param {*} [ctx] | ||
* @return {Model} | ||
*/ | ||
on: function (attribute, event, cb, ctx) { | ||
this._callEventEmitter('on', attribute, event, cb, ctx); | ||
return this; | ||
}, | ||
@@ -539,2 +545,4 @@ | ||
this._readyPromise = this._calculate(); | ||
} else { | ||
this._requireMoreCalculations = true; | ||
} | ||
@@ -558,2 +566,8 @@ if (this.throwCalculationErrors) { | ||
/** | ||
* marker that requires one more calculation cycle | ||
* @type {Boolean} | ||
*/ | ||
_requireMoreCalculations: false, | ||
/** | ||
* @param {Number} [n = 0] itteration | ||
@@ -593,3 +607,4 @@ * @return {Promise} | ||
model.set(calculateData); | ||
if (model.isChanged(model.CALCULATIONS_BRANCH)) { | ||
if (model.isChanged(model.CALCULATIONS_BRANCH) || model._requireMoreCalculations) { | ||
model._requireMoreCalculations = false; | ||
return model._calculate(++n); | ||
@@ -677,2 +692,13 @@ } else { | ||
/** | ||
* @return {Promise} | ||
*/ | ||
_rejectDestructed: function () { | ||
if (this.isDestructed()) { | ||
return Vow.reject(new Error ('Model is destructed')); | ||
} else { | ||
return Vow.fulfill(); | ||
} | ||
}, | ||
_throwMissedAttribute: function (attributeName) { | ||
@@ -687,2 +713,12 @@ if (!this.attributes[attributeName]) { | ||
/** | ||
* @override | ||
*/ | ||
inherit: function (props, staticProps) { | ||
staticProps = staticProps || {}; | ||
staticProps.attributes = staticProps.attributes || props.attributes; | ||
staticProps.storage = staticProps.storage || props.storage; | ||
return this.__base(props, staticProps); | ||
}, | ||
/** | ||
* @class | ||
@@ -689,0 +725,0 @@ * @abstract |
{ | ||
"description": "BEM wrapper for promised-models", | ||
"name": "bem-promised-models", | ||
"version": "0.0.13", | ||
"version": "0.0.14", | ||
"repository": "git@github.com:delfrrr/bem-promised-models.git", | ||
@@ -31,3 +31,3 @@ "keywords": [ | ||
"dependencies": { | ||
"promised-models": "0.0.11" | ||
"promised-models": "0.0.12" | ||
}, | ||
@@ -34,0 +34,0 @@ "devDependencies": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
53481
1596
+ Addedpromised-models@0.0.12(transitive)
- Removedpromised-models@0.0.11(transitive)
Updatedpromised-models@0.0.12