From e4d0d7a649df18252584b2f1ffda28cb532f753f Mon Sep 17 00:00:00 2001 From: yann300 Date: Wed, 12 Aug 2020 09:50:03 +0200 Subject: [PATCH] remove remix-lib dep from remix-solidity --- libs/remix-solidity/package.json | 1 - libs/remix-solidity/src/compiler/compiler.ts | 2 +- libs/remix-solidity/src/lib/eventManager.js | 70 ++++++++++++++++++++ 3 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 libs/remix-solidity/src/lib/eventManager.js diff --git a/libs/remix-solidity/package.json b/libs/remix-solidity/package.json index 0a8e07033f..e2e55b091e 100644 --- a/libs/remix-solidity/package.json +++ b/libs/remix-solidity/package.json @@ -16,7 +16,6 @@ ], "dependencies": { "eslint-scope": "^5.0.0", - "@remix-project/remix-lib": "0.4.30", "solc": "^0.6.0", "webworkify-webpack": "^2.1.5" }, diff --git a/libs/remix-solidity/src/compiler/compiler.ts b/libs/remix-solidity/src/compiler/compiler.ts index 1a5886537f..71a036a5e6 100644 --- a/libs/remix-solidity/src/compiler/compiler.ts +++ b/libs/remix-solidity/src/compiler/compiler.ts @@ -3,7 +3,7 @@ import { update } from 'solc/abi' import * as webworkify from 'webworkify-webpack' import compilerInput from './compiler-input' -import { EventManager } from '@remix-project/remix-lib' +import { EventManager } from '../lib/eventManager' import { default as txHelper } from './txHelper'; import { Source, SourceWithTarget, MessageFromWorker, CompilerState, CompilationResult, visitContractsCallbackParam, visitContractsCallbackInterface, CompilationError, diff --git a/libs/remix-solidity/src/lib/eventManager.js b/libs/remix-solidity/src/lib/eventManager.js new file mode 100644 index 0000000000..8d1ffb9e37 --- /dev/null +++ b/libs/remix-solidity/src/lib/eventManager.js @@ -0,0 +1,70 @@ +'use strict' + +function eventManager () { + this.registered = {} + this.anonymous = {} +} + +/* + * Unregister a listener. + * Note that if obj is a function. the unregistration will be applied to the dummy obj {}. + * + * @param {String} eventName - the event name + * @param {Object or Func} obj - object that will listen on this event + * @param {Func} func - function of the listeners that will be executed +*/ +eventManager.prototype.unregister = function (eventName, obj, func) { + if (!this.registered[eventName]) { + return + } + if (obj instanceof Function) { + func = obj + obj = this.anonymous + } + for (let reg in this.registered[eventName]) { + if (this.registered[eventName][reg].obj === obj && this.registered[eventName][reg].func === func) { + this.registered[eventName].splice(reg, 1) + } + } +} + +/* + * Register a new listener. + * Note that if obj is a function, the function registration will be associated with the dummy object {} + * + * @param {String} eventName - the event name + * @param {Object or Func} obj - object that will listen on this event + * @param {Func} func - function of the listeners that will be executed +*/ +eventManager.prototype.register = function (eventName, obj, func) { + if (!this.registered[eventName]) { + this.registered[eventName] = [] + } + if (obj instanceof Function) { + func = obj + obj = this.anonymous + } + this.registered[eventName].push({ + obj: obj, + func: func + }) +} + +/* + * trigger event. + * Every listener have their associated function executed + * + * @param {String} eventName - the event name + * @param {Array}j - argument that will be passed to the executed function. +*/ +eventManager.prototype.trigger = function (eventName, args) { + if (!this.registered[eventName]) { + return + } + for (let listener in this.registered[eventName]) { + const l = this.registered[eventName][listener] + l.func.apply(l.obj === this.anonymous ? {} : l.obj, args) + } +} + +module.exports = eventManager \ No newline at end of file