bem-promised-models
Advanced tools
Comparing version 0.0.18 to 0.0.19
@@ -384,3 +384,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){ | ||
var model = this; | ||
return fulfill().then(function () { | ||
return this.ready().then(function () { | ||
return model.storage.find(model); | ||
@@ -604,5 +604,9 @@ }).then(function (data) { | ||
calculate: function () { | ||
var model = this; | ||
if (this.isReady()) { | ||
this.trigger('calculate'); | ||
this._readyPromise = this._calculate(); | ||
//start _calculate on next tick | ||
this._readyPromise = fulfill().then(function () { | ||
return model._calculate(); | ||
}); | ||
} else { | ||
@@ -649,2 +653,4 @@ this._requireMoreCalculations = true; | ||
this._requireMoreCalculations = false; | ||
model.commit(model.CALCULATIONS_BRANCH); | ||
@@ -668,3 +674,4 @@ | ||
]).spread(function (calculateData) { | ||
model.set(calculateData); | ||
model._setCalculatedData(calculateData); | ||
// model.set(calculateData); | ||
if (model._checkContinueCalculations()) { | ||
@@ -682,6 +689,15 @@ return model._calculate(++n); | ||
/** | ||
* setting calculated data only if nothing have changed during calculations | ||
* otherwise we will have racing conditions( | ||
* @param {object} calculateData | ||
*/ | ||
_setCalculatedData: function (calculateData) { | ||
if (!this._checkContinueCalculations()) { | ||
this.set(calculateData); | ||
} | ||
}, | ||
_checkContinueCalculations: function () { | ||
var toContinue = this.isChanged(this.CALCULATIONS_BRANCH) || this._requireMoreCalculations; | ||
this._requireMoreCalculations = false; | ||
return toContinue; | ||
return this.isChanged(this.CALCULATIONS_BRANCH) || this._requireMoreCalculations; | ||
}, | ||
@@ -688,0 +704,0 @@ |
{ | ||
"description": "BEM wrapper for promised-models", | ||
"name": "bem-promised-models", | ||
"version": "0.0.18", | ||
"version": "0.0.19", | ||
"repository": "git@github.com:delfrrr/bem-promised-models.git", | ||
@@ -31,3 +31,3 @@ "keywords": [ | ||
"dependencies": { | ||
"promised-models": "0.0.16" | ||
"promised-models": "0.0.17" | ||
}, | ||
@@ -34,0 +34,0 @@ "devDependencies": { |
@@ -106,3 +106,3 @@ # bem-promised-models | ||
### Pass models by client id (for broser render only) | ||
### Pass models by client id (for browser render only) | ||
@@ -162,3 +162,3 @@ ``` | ||
Adds model declaration | ||
Add model declaration | ||
@@ -181,3 +181,3 @@ #### `.getOne([cid])` | ||
Get model instance by storage id `model.id`. If no instance with `id` was found, creates new one. | ||
Get model instance by storage id `model.id`. If no instance with `id` was found, create new one. | ||
@@ -184,0 +184,0 @@ |
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
56692
1702
+ Addedpromised-models@0.0.17(transitive)
- Removedpromised-models@0.0.16(transitive)
Updatedpromised-models@0.0.17