Field updates now idempotent per Immutable.is

This commit is contained in:
Tony Garnock-Jones 2018-11-26 13:13:25 +00:00
parent 727fdd33e6
commit 0eb9205a19
1 changed files with 10 additions and 7 deletions

View File

@ -18,7 +18,7 @@
//---------------------------------------------------------------------------
const Immutable = require("immutable");
const { fromJS } = require("preserves");
const Preserves = require("preserves");
const Skeleton = require('./skeleton.js');
const $Special = require('./special.js');
@ -130,7 +130,10 @@ Dataspace.declareField = function (obj, prop, init) {
obj,
prop,
init,
{ objectId: Immutable.List.of(obj, prop) });
{
objectId: Immutable.List.of(obj, prop),
noopGuard: Preserves.is
});
}
};
@ -344,14 +347,14 @@ Actor.prototype.assert = function (a) { this.pendingPatch().adjust(a, +1); };
Actor.prototype.retract = function (a) { this.pendingPatch().adjust(a, -1); };
Actor.prototype.adhocRetract = function (a) {
a = fromJS(a);
a = Preserves.fromJS(a);
if (this.adhocAssertions.change(a, -1, true) === Bag.PRESENT_TO_ABSENT) {
this.retract(a);
}
};
Actor.prototype.adhocAssert = function (a) {
a = fromJS(a);
a = Preserves.fromJS(a);
if (this.adhocAssertions.change(a, +1) === Bag.ABSENT_TO_PRESENT) {
this.assert(a);
}
@ -374,7 +377,7 @@ Patch.prototype.perform = function (ds, ac) {
Patch.prototype.adjust = function (a, count) {
if (a !== void 0) {
var _net;
({bag: this.changes, net: _net} = Bag.change(this.changes, fromJS(a), count));
({bag: this.changes, net: _net} = Bag.change(this.changes, Preserves.fromJS(a), count));
}
};
@ -384,7 +387,7 @@ function Message(body) {
Message.prototype.perform = function (ds, ac) {
if (this.body !== void 0) {
ds.sendMessage(fromJS(this.body));
ds.sendMessage(Preserves.fromJS(this.body));
}
};
@ -617,7 +620,7 @@ Endpoint.prototype._uninstall = function (ds, ac, emitPatches) {
Endpoint.prototype.refresh = function (ds, ac, facet) {
let [newAssertion, newHandler] = this.updateFun.call(facet.fields);
if (newAssertion !== void 0) newAssertion = fromJS(newAssertion);
if (newAssertion !== void 0) newAssertion = Preserves.fromJS(newAssertion);
if (!Immutable.is(newAssertion, this.assertion)) {
this._uninstall(ds, ac, true);
this._install(ds, ac, newAssertion, newHandler);