From 3e16d7e976a64a3392428de3b2dd66073e61af0d Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 2 Jul 2018 17:13:21 +0200 Subject: [PATCH] comment moduleid && and use minimal registry --- src/app/editor/editor.js | 7 +++-- src/module-id.js | 3 ++ src/registry.js | 59 ++++++++-------------------------------- 3 files changed, 18 insertions(+), 51 deletions(-) diff --git a/src/app/editor/editor.js b/src/app/editor/editor.js index f56f0341cc..98c1630e8d 100644 --- a/src/app/editor/editor.js +++ b/src/app/editor/editor.js @@ -1,4 +1,6 @@ 'use strict' +var remixLib = require('remix-lib') +var EventManager = remixLib.EventManager var yo = require('yo-yo') var csjs = require('csjs-inject') var ace = require('brace') @@ -65,9 +67,6 @@ document.head.appendChild(yo` function Editor (opts = {}) { var self = this - var eventsName = ['breakpointCleared', 'breakpointAdded', 'sessionSwitched', 'contentChanged'] // not used for legacyEvent - var {legacyEvents} = registry.put({api: this, events: eventsName, name: 'editor'}) - self.event = legacyEvents var el = yo`
` var editor = ace.edit(el) if (styles.appProperties.aceTheme) { @@ -84,6 +83,8 @@ function Editor (opts = {}) { // @TODO add here other propositions } } + var event = new EventManager() + self.event = event langTools.addCompleter(flowCompleter) el.className += ' ' + css['ace-editor'] el.editor = editor // required to access the editor during tests diff --git a/src/module-id.js b/src/module-id.js index 5aea03205e..efa2e63238 100644 --- a/src/module-id.js +++ b/src/module-id.js @@ -1,4 +1,7 @@ module.exports = stacktrace +/* + Not used yet +*/ function stacktrace () { var _ = Error.prepareStackTrace Error.prepareStackTrace = (_, stack) => stack diff --git a/src/registry.js b/src/registry.js index be2fbea5cc..951d076165 100644 --- a/src/registry.js +++ b/src/registry.js @@ -1,61 +1,24 @@ -const moduleID = require('./module-id.js') -const remixLib = require('remix-lib') -const EventManager = remixLib.EventManager +// const moduleID = require('./module-id.js') module.exports = class registry { constructor () { this.state = {} } - put ({ api, events, name }) { - const serveruid = moduleID() + '.' + (name || '') - console.log('registering ', serveruid) - if (this.state[serveruid]) return this.state[serveruid] + put ({ api, name }) { + // const serveruid = moduleID() + '.' + (name || '') + if (this.state[name]) return this.state[name] const server = { - uid: serveruid, - // api: new ApiManager(api), - events: makeEvents(events), - legacyEvents: api.event ? api.event : new EventManager() - } - this.state[serveruid] = { - _name: name, - _api: api, - _events: events, - server: server, - clients: [] + // uid: serveruid, + api } + this.state[name] = { server } return server } - get (uid) { - const clientuid = moduleID() - const state = this.state[uid] + get (name) { + // const clientuid = moduleID() + const state = this.state[name] if (!state) return const server = state.server - const client = { - uid: clientuid, - api: state._api, - events: server.events, - legacyEvents: server.legacyEvents - } - server.clients.push(client) - return client + return server } } - -function makeEvents (events) { - if (!events) return [] - function update (name) { update[name] = new EventManager() } - return events.reduce((fn, x) => { - fn[x] = new EventManager() - var oldTrigger = fn[x].trigger - fn[x].trigger = (name, args) => { - console.log(name) - oldTrigger.call(fn[x], name, args) - } - var oldRegister = fn[x].register - fn[x].register = (name, obj, fn) => { - console.log(name) - oldRegister.call(fn[x], obj, fn) - } - return fn - }, update) -}