Field updates now idempotent per Immutable.is
This commit is contained in:
parent
727fdd33e6
commit
0eb9205a19
|
@ -18,7 +18,7 @@
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
const Immutable = require("immutable");
|
const Immutable = require("immutable");
|
||||||
const { fromJS } = require("preserves");
|
const Preserves = require("preserves");
|
||||||
|
|
||||||
const Skeleton = require('./skeleton.js');
|
const Skeleton = require('./skeleton.js');
|
||||||
const $Special = require('./special.js');
|
const $Special = require('./special.js');
|
||||||
|
@ -130,7 +130,10 @@ Dataspace.declareField = function (obj, prop, init) {
|
||||||
obj,
|
obj,
|
||||||
prop,
|
prop,
|
||||||
init,
|
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.retract = function (a) { this.pendingPatch().adjust(a, -1); };
|
||||||
|
|
||||||
Actor.prototype.adhocRetract = function (a) {
|
Actor.prototype.adhocRetract = function (a) {
|
||||||
a = fromJS(a);
|
a = Preserves.fromJS(a);
|
||||||
if (this.adhocAssertions.change(a, -1, true) === Bag.PRESENT_TO_ABSENT) {
|
if (this.adhocAssertions.change(a, -1, true) === Bag.PRESENT_TO_ABSENT) {
|
||||||
this.retract(a);
|
this.retract(a);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Actor.prototype.adhocAssert = function (a) {
|
Actor.prototype.adhocAssert = function (a) {
|
||||||
a = fromJS(a);
|
a = Preserves.fromJS(a);
|
||||||
if (this.adhocAssertions.change(a, +1) === Bag.ABSENT_TO_PRESENT) {
|
if (this.adhocAssertions.change(a, +1) === Bag.ABSENT_TO_PRESENT) {
|
||||||
this.assert(a);
|
this.assert(a);
|
||||||
}
|
}
|
||||||
|
@ -374,7 +377,7 @@ Patch.prototype.perform = function (ds, ac) {
|
||||||
Patch.prototype.adjust = function (a, count) {
|
Patch.prototype.adjust = function (a, count) {
|
||||||
if (a !== void 0) {
|
if (a !== void 0) {
|
||||||
var _net;
|
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) {
|
Message.prototype.perform = function (ds, ac) {
|
||||||
if (this.body !== void 0) {
|
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) {
|
Endpoint.prototype.refresh = function (ds, ac, facet) {
|
||||||
let [newAssertion, newHandler] = this.updateFun.call(facet.fields);
|
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)) {
|
if (!Immutable.is(newAssertion, this.assertion)) {
|
||||||
this._uninstall(ds, ac, true);
|
this._uninstall(ds, ac, true);
|
||||||
this._install(ds, ac, newAssertion, newHandler);
|
this._install(ds, ac, newAssertion, newHandler);
|
||||||
|
|
Loading…
Reference in New Issue