add registry

pull/1/head
yann300 7 years ago
parent 51519c6c86
commit 13ee679c19
  1. 2
      src/app.js
  2. 18
      src/app/editor/editor.js
  3. 1
      src/global/registry.js
  4. 8
      src/module-id.js
  5. 62
      src/registry.js

@ -9,6 +9,7 @@ var remixLib = require('remix-lib')
var remixTests = require('remix-tests')
var EventManager = remixLib.EventManager
var registry = require('./global/registry')
var UniversalDApp = require('./universal-dapp.js')
var UniversalDAppUI = require('./universal-dapp-ui.js')
var Remixd = require('./lib/remixd')
@ -293,6 +294,7 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
// ----------------- Compiler -----------------
var compiler = new Compiler(importFileCb)
registry.put({api: compiler, name: 'compiler'})
var offsetToLineColumnConverter = new OffsetToLineColumnConverter(compiler.event)
// ----------------- UniversalDApp -----------------

@ -1,9 +1,8 @@
'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')
var registry = require('../../global/registry')
require('brace/theme/tomorrow_night_blue')
@ -65,6 +64,10 @@ document.head.appendChild(yo`
function Editor (opts = {}) {
var self = this
var eventsName = ['breakpointCleared', 'breakpointAdded', 'sessionSwitched', 'contentChanged'] // not used for legacyEvent
var {uid /* api, */, legacyEvents} = registry.put({api: this, events: eventsName, name: 'editor'})
self.event = legacyEvents
var el = yo`<div id="input"></div>`
var editor = ace.edit(el)
if (styles.appProperties.aceTheme) {
@ -85,8 +88,7 @@ function Editor (opts = {}) {
el.className += ' ' + css['ace-editor']
el.editor = editor // required to access the editor during tests
self.render = function () { return el }
var event = new EventManager()
self.event = event
var sessions = {}
var sourceAnnotations = []
var readOnlySessions = {}
@ -103,14 +105,14 @@ function Editor (opts = {}) {
var breakpoints = e.editor.session.getBreakpoints()
for (var k in breakpoints) {
if (k === row.toString()) {
event.trigger('breakpointCleared', [currentSession, row])
self.event.trigger('breakpointCleared', [currentSession, row])
e.editor.session.clearBreakpoint(row)
e.stop()
return
}
}
self.setBreakpoint(row)
event.trigger('breakpointAdded', [currentSession, row])
self.event.trigger('breakpointAdded', [currentSession, row])
e.stop()
})
@ -277,10 +279,10 @@ function Editor (opts = {}) {
// Do setup on initialisation here
editor.on('changeSession', function () {
event.trigger('sessionSwitched', [])
self.event.trigger('sessionSwitched', [])
editor.getSession().on('change', function () {
event.trigger('contentChanged', [])
self.event.trigger('contentChanged', [])
})
})

@ -0,0 +1 @@
module.exports = new (require('../registry.js'))()

@ -0,0 +1,8 @@
module.exports = stacktrace
function stacktrace () {
var _ = Error.prepareStackTrace
Error.prepareStackTrace = (_, stack) => stack
var callsites = new Error().stack
Error.prepareStackTrace = _
return callsites.slice(2).map(x => { return x.getFunctionName() }).reverse().join('.')
}

@ -0,0 +1,62 @@
const moduleID = require('./module-id.js')
const remixLib = require('remix-lib')
const EventManager = remixLib.EventManager
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]
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: []
}
return server
}
get (uid) {
const clientuid = moduleID()
const state = this.state[uid]
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
}
}
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)
}
Loading…
Cancel
Save