Debug output

This commit is contained in:
Tony Garnock-Jones 2019-05-30 22:52:31 +01:00
parent 33dd38aea6
commit 0f6987b02d
2 changed files with 11 additions and 0 deletions

View File

@ -21,6 +21,7 @@
"nyc": "^14.1.1" "nyc": "^14.1.1"
}, },
"dependencies": { "dependencies": {
"debug": "^4.1.1",
"immutable": "^3.8.2", "immutable": "^3.8.2",
"preserves": "0.0.8" "preserves": "0.0.8"
} }

View File

@ -19,6 +19,7 @@
const Immutable = require("immutable"); const Immutable = require("immutable");
const Preserves = require("preserves"); const Preserves = require("preserves");
const debug = require("debug")("syndicate/core:dataspace");
const Skeleton = require('./skeleton.js'); const Skeleton = require('./skeleton.js');
const $Special = require('./special.js'); const $Special = require('./special.js');
@ -188,6 +189,7 @@ Dataspace.prototype.refreshAssertions = function () {
Dataspace.prototype.addActor = function (name, bootProc, initialAssertions, parentActor) { Dataspace.prototype.addActor = function (name, bootProc, initialAssertions, parentActor) {
let ac = new Actor(this, name, initialAssertions, parentActor && parentActor.id); let ac = new Actor(this, name, initialAssertions, parentActor && parentActor.id);
debug('Spawn', ac && ac.toString());
this.applyPatch(ac, ac.adhocAssertions.snapshot()); this.applyPatch(ac, ac.adhocAssertions.snapshot());
ac.addFacet(null, () => { ac.addFacet(null, () => {
// Root facet is a dummy "system" facet that exists to hold // 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) { Dataspace.prototype.applyPatch = function (ac, delta) {
if (!delta.isEmpty()) debug('applyPatch BEGIN', ac && ac.toString());
let removals = []; let removals = [];
delta.forEach((count, a) => { delta.forEach((count, a) => {
if (a !== void 0) { if (a !== void 0) {
if (count > 0) { if (count > 0) {
debug('applyPatch +', a && a.toString());
this.adjustIndex(a, count); this.adjustIndex(a, count);
} else { } else {
removals.push([count, a]); removals.push([count, a]);
@ -211,11 +215,14 @@ Dataspace.prototype.applyPatch = function (ac, delta) {
} }
}); });
removals.forEach(([count, a]) => { removals.forEach(([count, a]) => {
debug('applyPatch -', a && a.toString());
this.adjustIndex(a, count); this.adjustIndex(a, count);
}); });
if (!delta.isEmpty()) debug('applyPatch END');
}; };
Dataspace.prototype.sendMessage = function (m, sendingActor) { Dataspace.prototype.sendMessage = function (m, sendingActor) {
debug('sendMessage', sendingActor && sendingActor.toString(), m.toString());
this.index.sendMessage(m); this.index.sendMessage(m);
// this.index.sendMessage(m, (leaf, _m) => { // this.index.sendMessage(m, (leaf, _m) => {
// sendingActor.touchedTopics = sendingActor.touchedTopics.add(leaf); // sendingActor.touchedTopics = sendingActor.touchedTopics.add(leaf);
@ -576,6 +583,7 @@ function Quit() { // TODO: rename? Perhaps to Cleanup?
Quit.prototype.perform = function (ds, ac) { Quit.prototype.perform = function (ds, ac) {
ds.applyPatch(ac, ac.cleanupChanges.snapshot()); ds.applyPatch(ac, ac.cleanupChanges.snapshot());
ds.actors = ds.actors.remove(ac.id); ds.actors = ds.actors.remove(ac.id);
debug('Quit', ac && ac.toString());
}; };
function DeferredTurn(continuation) { function DeferredTurn(continuation) {
@ -583,6 +591,7 @@ function DeferredTurn(continuation) {
} }
DeferredTurn.prototype.perform = function (ds, ac) { DeferredTurn.prototype.perform = function (ds, ac) {
debug('DeferredTurn', ac && ac.toString());
ac.pushScript(this.continuation); ac.pushScript(this.continuation);
}; };
@ -599,6 +608,7 @@ function Activation(mod) {
Activation.prototype.perform = function (ds, ac) { Activation.prototype.perform = function (ds, ac) {
if (!ds.activatedModules.includes(this.mod)) { if (!ds.activatedModules.includes(this.mod)) {
debug('Activation', this.mod.id);
ds.activatedModules = ds.activatedModules.add(this.mod); ds.activatedModules = ds.activatedModules.add(this.mod);
this.mod.exports[Dataspace.BootSteps].steps.forEach((a) => { this.mod.exports[Dataspace.BootSteps].steps.forEach((a) => {
// console.log('[ACTIVATION]', ac && ac.toString(), a); // console.log('[ACTIVATION]', ac && ac.toString(), a);