From 39ab3cb56d2f0cf4cb4c07b83ab15fd5c88180cc Mon Sep 17 00:00:00 2001 From: Marcus Date: Thu, 17 Oct 2019 14:50:16 -0400 Subject: [PATCH] For Trevor --- .vscode/launch.json | 14 +++++ core/Collexion.js | 107 +++++++++++++------------------------ package.json | 1 - tests/pingpong/index.js | 20 +++---- tests/pingpong/pingpong.js | 4 +- 5 files changed, 59 insertions(+), 87 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..c066264 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,14 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Test", + "program": "${workspaceFolder}\\tests\\pingpong\\index.js" + } + ] +} \ No newline at end of file diff --git a/core/Collexion.js b/core/Collexion.js index 0b9b7e6..bc62f4f 100644 --- a/core/Collexion.js +++ b/core/Collexion.js @@ -1,83 +1,48 @@ const {Signale} = require('signale'); const log = new Signale({ - scope: 'COLLEXION' + scope: 'CORE' }); -const path = require('path'); -const fs = require('fs'); -const uuid = require('uuid'); -const root = (typeof window === 'undefined' ? global : window) -const {Entity} = require('./entity.js') - -class Link { - constructor(symbol) { - this.symbol = symbol; - } - - toString() { - return "" + this.symbol; - } -} class Collexion { - constructor() { - // this.cache = cache; + constructor(template) { this.entities = {}; - // for(const uuid of cache.getInstances()) { - // this.loadEntity(uuid) - // } - } + (async () => { + const instances = {}; + + log.info('Starting Collexion with ' + Object.keys(template) + ' Objects') - createInstances(template) { - const instances = {}; - - for(const symbol in template) { - const instTemplate = template[symbol]; - const _class = instTemplate.Code; - const inst = new _class(this); - inst._data = instTemplate.Data; - instances[symbol] = inst; - } - - for(const symbol in instances) { - const inst = instances[symbol]; - inst.start() - } - - for(const symbol in instances) { - const inst = instances[symbol]; - const instTemplate = template[symbol]; - inst._links = instTemplate.Links; - - for (const linkKey in inst._links) { - const link = inst._links[linkKey]; - inst._links[linkKey] = instances[link]; + // call constructors on objects, and give them their data + for(const symbol in template) { + const instTemplate = template[symbol]; + const _class = instTemplate.Code; + const inst = new _class(this); + // guarantee at least an object in _data + inst._data = {...instTemplate.Data}; + instances[symbol] = inst; } - } - for(const symbol in instances) { - const inst = instances[symbol]; - inst.connected() - } + //call start in each instance. + for(const symbol in instances) { + const inst = instances[symbol]; + if('start' in inst) + await inst.start() + } + + for(const symbol in instances) { + const inst = instances[symbol]; + for(const symbol in instances) { + inst[symbol] = instances[symbol]; + } + } + + for(const symbol in instances) { + const inst = instances[symbol]; + if('connected' in inst) + await inst.connected() + } + + })(); } - - loadEntity(uuid) { - // log.debug(`spinning up ${uuid}`); - log.debug(uuid) - if(typeof require === 'function') { - let codePath = this.cache.getEntityCodePathFromUuid(uuid); - // log.debug(codePath) - let data = this.cache.getDataFromUuid(uuid); - let instanceData = this.cache.getInstanceFromUuid(uuid); - let userCode = require(codePath).entity; - this.entities[uuid] = new Entity(userCode, instanceData, this); - this.entities[uuid].start(); - log.debug('starting', uuid) - } else { - //TODO COMPLICATED EVAL SHIT, MIRRORING REQUIRE FUNCTIONALITY - } - } - - } -module.exports = {Collexion, Link}; \ No newline at end of file +module.exports = {Collexion, Link, Component}; \ No newline at end of file diff --git a/package.json b/package.json index 43def17..56d55a1 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,6 @@ }, "homepage": "https://github.com/marcus13345/AquaTin#readme", "dependencies": { - "aquatin": "file:.", "rimraf": "^2.6.3", "signale": "^1.4.0", "typescript": "^3.5.3", diff --git a/tests/pingpong/index.js b/tests/pingpong/index.js index 3d66312..358afbf 100644 --- a/tests/pingpong/index.js +++ b/tests/pingpong/index.js @@ -2,27 +2,21 @@ const {Collexion, Link, LinkArray} = require('./../../core/Collexion.js'); const PingPong = require('./pingpong.js') ;(async () => { - const collexion = new Collexion({}); - collexion.createInstances({ - 'A': { + const collexion = new Collexion({ + A: { Code: PingPong, Data: { - boop: true - }, - Links: { - thing: new Link('B') + start: true, + boop: 'B' } }, - 'B': { + B: { Code: PingPong, Data: { - - }, - Links: { - thing: new Link('B') + boop: 'A' } } - }) + }); })(); diff --git a/tests/pingpong/pingpong.js b/tests/pingpong/pingpong.js index 2e1c96f..b584841 100644 --- a/tests/pingpong/pingpong.js +++ b/tests/pingpong/pingpong.js @@ -5,7 +5,7 @@ const log = new Signale({ module.exports = class module { async start() { - console.log(this._data) + // console.log(this._data) } connected() { @@ -16,7 +16,7 @@ module.exports = class module { async boop() { log.info(`Boop!`) await new Promise(res => setTimeout(res, 1000)); - this._links.thing.boop(); + this[this.boop].boop(); } }