diff --git a/packages/core/package.json b/packages/core/package.json index c412139..186fe0c 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -21,6 +21,7 @@ "nyc": "^14.1.1" }, "dependencies": { + "debug": "^4.1.1", "immutable": "^3.8.2", "preserves": "0.0.8" } diff --git a/packages/core/src/dataspace.js b/packages/core/src/dataspace.js index 5c729d2..0f8420b 100644 --- a/packages/core/src/dataspace.js +++ b/packages/core/src/dataspace.js @@ -19,6 +19,7 @@ const Immutable = require("immutable"); const Preserves = require("preserves"); +const debug = require("debug")("syndicate/core:dataspace"); const Skeleton = require('./skeleton.js'); const $Special = require('./special.js'); @@ -188,6 +189,7 @@ Dataspace.prototype.refreshAssertions = function () { Dataspace.prototype.addActor = function (name, bootProc, initialAssertions, parentActor) { let ac = new Actor(this, name, initialAssertions, parentActor && parentActor.id); + debug('Spawn', ac && ac.toString()); this.applyPatch(ac, ac.adhocAssertions.snapshot()); ac.addFacet(null, () => { // Root facet is a dummy "system" facet that exists to hold @@ -199,10 +201,12 @@ Dataspace.prototype.addActor = function (name, bootProc, initialAssertions, pare }; Dataspace.prototype.applyPatch = function (ac, delta) { + if (!delta.isEmpty()) debug('applyPatch BEGIN', ac && ac.toString()); let removals = []; delta.forEach((count, a) => { if (a !== void 0) { if (count > 0) { + debug('applyPatch +', a && a.toString()); this.adjustIndex(a, count); } else { removals.push([count, a]); @@ -211,11 +215,14 @@ Dataspace.prototype.applyPatch = function (ac, delta) { } }); removals.forEach(([count, a]) => { + debug('applyPatch -', a && a.toString()); this.adjustIndex(a, count); }); + if (!delta.isEmpty()) debug('applyPatch END'); }; Dataspace.prototype.sendMessage = function (m, sendingActor) { + debug('sendMessage', sendingActor && sendingActor.toString(), m.toString()); this.index.sendMessage(m); // this.index.sendMessage(m, (leaf, _m) => { // sendingActor.touchedTopics = sendingActor.touchedTopics.add(leaf); @@ -576,6 +583,7 @@ function Quit() { // TODO: rename? Perhaps to Cleanup? Quit.prototype.perform = function (ds, ac) { ds.applyPatch(ac, ac.cleanupChanges.snapshot()); ds.actors = ds.actors.remove(ac.id); + debug('Quit', ac && ac.toString()); }; function DeferredTurn(continuation) { @@ -583,6 +591,7 @@ function DeferredTurn(continuation) { } DeferredTurn.prototype.perform = function (ds, ac) { + debug('DeferredTurn', ac && ac.toString()); ac.pushScript(this.continuation); }; @@ -599,6 +608,7 @@ function Activation(mod) { Activation.prototype.perform = function (ds, ac) { if (!ds.activatedModules.includes(this.mod)) { + debug('Activation', this.mod.id); ds.activatedModules = ds.activatedModules.add(this.mod); this.mod.exports[Dataspace.BootSteps].steps.forEach((a) => { // console.log('[ACTIVATION]', ac && ac.toString(), a);