Comparing version 6.0.1 to 7.0.0
# Changelog | ||
## `7.0.0`` | ||
- Breaking: Moved indexes as getters so they are available during the first `Collection#set` call in the constructor | ||
- Refactored `Collection#set` to batch all the additions so indexes are not recalculated for each addition. | ||
- Refactored `Model#constructor` to directly set the attributes instead of initialize with an empty map and replace it. | ||
## `6.0.1`` | ||
@@ -4,0 +10,0 @@ |
@@ -10,6 +10,6 @@ import Base from './Base'; | ||
models: IObservableArray<T>; | ||
indexes: Array<string>; | ||
constructor(data?: Array<{ | ||
[key: string]: any; | ||
}>); | ||
readonly indexes: Array<string>; | ||
/** | ||
@@ -16,0 +16,0 @@ * Define which is the primary key |
@@ -229,4 +229,2 @@ 'use strict'; | ||
_this.defaultAttributes = {}; | ||
_this.attributes = mobx.observable.map(); | ||
_this.committedAttributes = mobx.observable.map(); | ||
_this.optimisticId = uniqueId('i_'); | ||
@@ -236,4 +234,4 @@ _this.collection = null; | ||
var mergedAttributes = __assign({}, _this.defaultAttributes, attributes); | ||
_this.attributes.replace(mergedAttributes); | ||
_this.commitChanges(); | ||
_this.attributes = mobx.observable.map(mergedAttributes); | ||
_this.committedAttributes = mobx.observable.map(mergedAttributes); | ||
return _this; | ||
@@ -580,6 +578,15 @@ } | ||
_this.models = mobx.observable.array([]); | ||
_this.indexes = []; | ||
_this.set(data); | ||
return _this; | ||
} | ||
Object.defineProperty(Collection.prototype, "indexes", { | ||
/* | ||
* Override this to have more indexes | ||
*/ | ||
get: function () { | ||
return []; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Collection.prototype, "primaryKey", { | ||
@@ -806,12 +813,7 @@ /** | ||
var _b = _a === void 0 ? {} : _a, _c = _b.add, add = _c === void 0 ? true : _c, _d = _b.change, change = _d === void 0 ? true : _d, _e = _b.remove, remove = _e === void 0 ? true : _e; | ||
if (remove) { | ||
var ids = compact(resources.map(function (r) { | ||
return getAttribute(r, _this.primaryKey); | ||
})); | ||
var toRemove = difference(this._ids, ids); | ||
if (toRemove.length) | ||
this.remove(toRemove); | ||
} | ||
var getPrimaryKey = function (resource) { return getAttribute(resource, _this.primaryKey); }; | ||
var idsToRemove = difference(this._ids, resources.map(getPrimaryKey)); | ||
var resourcesToAdd = []; | ||
resources.forEach(function (resource) { | ||
var id = getAttribute(resource, _this.primaryKey); | ||
var id = getPrimaryKey(resource); | ||
var model = id ? _this.get(id) : null; | ||
@@ -821,5 +823,12 @@ if (model && change) { | ||
} | ||
if (!model && add) | ||
_this.add([resource]); | ||
else { | ||
resourcesToAdd.push(resource); | ||
} | ||
}); | ||
if (remove && idsToRemove.length) { | ||
this.remove(idsToRemove); | ||
} | ||
if (add && resourcesToAdd.length) { | ||
this.add(resourcesToAdd); | ||
} | ||
}; | ||
@@ -883,5 +892,2 @@ /** | ||
__decorate([ | ||
mobx.observable | ||
], Collection.prototype, "models", void 0); | ||
__decorate([ | ||
mobx.computed({ keepAlive: true }) | ||
@@ -888,0 +894,0 @@ ], Collection.prototype, "index", null); |
{ | ||
"name": "mobx-rest", | ||
"version": "6.0.1", | ||
"version": "7.0.0", | ||
"description": "REST conventions for mobx.", | ||
@@ -5,0 +5,0 @@ "jest": { |
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
71262
1280