From 782d97a3babbd6ae0855ed77a67a49bd87a9859d Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Fri, 14 Jun 2019 13:06:40 +0100 Subject: [PATCH] Still whacking away at the singleton issue --- packages/core/package.json | 2 +- packages/core/src/dataspace.js | 38 +++++----------------------------- 2 files changed, 6 insertions(+), 34 deletions(-) diff --git a/packages/core/package.json b/packages/core/package.json index c4a4076..2e1d66f 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -23,6 +23,6 @@ "dependencies": { "debug": "^4.1.1", "immutable": "^3.8.2", - "preserves": "0.0.11" + "preserves": "0.0.12" } } diff --git a/packages/core/src/dataspace.js b/packages/core/src/dataspace.js index 227aede..3db893d 100644 --- a/packages/core/src/dataspace.js +++ b/packages/core/src/dataspace.js @@ -17,6 +17,11 @@ // along with this program. If not, see . //--------------------------------------------------------------------------- +if (require('preserves/src/singletonmodule.js')('syndicate-lang.org/syndicate-js', + require('../package.json').version, + 'dataspace.js', + module)) return; + const Immutable = require("immutable"); const Preserves = require("preserves"); // const debug = require("debug")("syndicate/core:dataspace"); @@ -37,39 +42,6 @@ const PRIORITY = Object.freeze({ _count: 6 }); -// Singleton hackery. -const Dataspace = (function () { - const SYNDICATE = Symbol.for('@syndicate-lang/core'); - const version = require('../package.json').version; - if (!(SYNDICATE in global)) { - function Dataspace(bootProc) { - this.nextId = 0; - this.index = new Skeleton.Index(); - this.dataflow = new Dataflow.Graph(); - this.runnable = Immutable.List(); - this.pendingActions = Immutable.List([ - new ActionGroup(null, Immutable.List([new Spawn(null, bootProc, Immutable.Set())]))]); - this.activatedModules = Immutable.Set(); - this.actors = Immutable.Map(); - } - - // Parameters - Dataspace._currentFacet = null; - Dataspace._inScript = true; - - global[SYNDICATE] = { - version: version, - Dataspace: Dataspace, - }; - } - const g = global[SYNDICATE]; - if (g.version !== version) { - console.warn('Potentially incompatible versions of @syndicate-lang/core loaded:', - version, g.version); - } - return g.Dataspace; -})(); - Dataspace.BootSteps = Symbol.for('SyndicateBootSteps'); Dataspace.currentFacet = function () {