- change event manager creation process

- doc
pull/1/head
yann300 8 years ago
parent 9356a946e9
commit d172d68b71
  1. 4
      src/app.js
  2. 4
      src/app/compiler.js
  3. 4
      src/app/execution-context.js
  4. 4
      src/app/formalVerification.js
  5. 23
      src/lib/eventManager.js
  6. 5
      src/lib/util.js
  7. 4
      src/universal-dapp.js

@ -16,7 +16,7 @@ var ExecutionContext = require('./app/execution-context');
var UniversalDApp = require('./universal-dapp.js');
var Debugger = require('./app/debugger');
var FormalVerification = require('./app/formalVerification');
var util = require('./lib/util');
var EventManager = require('./lib/eventManager');
// The event listener needs to be registered as early as possible, because the
// parent will send the message upon the "load" event.
@ -32,7 +32,7 @@ window.addEventListener('message', function (ev) {
*/
var run = function () {
var self = this;
util.makeEventCapable(this);
this.event = new EventManager();
var storage = new Storage(updateFiles);
function loadFiles (files) {

@ -5,14 +5,14 @@ var utils = require('./utils');
var Base64 = require('js-base64').Base64;
var util = require('../lib/util');
var EventManager = require('../lib/eventManager');
/*
trigger compilationError, compilationSucceed, compilerLoaded, isCompiling
*/
function Compiler (editor, queryParams, handleGithubCall, updateFiles) {
var self = this;
util.makeEventCapable(this);
this.event = new EventManager();
var compileJSON;
var compilerAcceptsMultipleFiles;

@ -2,7 +2,7 @@
var $ = require('jquery');
var Web3 = require('web3');
var util = require('../lib/util');
var EventManager = require('../lib/eventManager');
var EthJSVM = require('ethereumjs-vm');
var injectedProvider;
@ -24,7 +24,7 @@ vm.stateManager.checkpoint();
function ExecutionContext () {
var self = this;
util.makeEventCapable(this);
this.event = new EventManager();
var executionContext = injectedProvider ? 'injected' : 'vm';
this.isVM = function () {

@ -1,11 +1,11 @@
var $ = require('jquery');
var util = require('../lib/util');
var EventManager = require('../lib/eventManager');
/*
trigger compilationError
*/
function FormalVerification (outputElement) {
util.makeEventCapable(this);
this.event = new EventManager();
this.outputElement = outputElement;
}

@ -3,6 +3,14 @@ function eventManager () {
this.registered = {};
}
/*
* Unregister a listenner.
* 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 listenners that will be executed
*/
eventManager.prototype.unregister = function (eventName, obj, func) {
if (obj instanceof Function) {
func = obj;
@ -17,6 +25,14 @@ eventManager.prototype.unregister = function (eventName, obj, func) {
}
};
/*
* Register a new listenner.
* 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 listenners that will be executed
*/
eventManager.prototype.register = function (eventName, obj, func) {
if (!this.registered[eventName]) {
this.registered[eventName] = [];
@ -31,6 +47,13 @@ eventManager.prototype.register = function (eventName, obj, func) {
});
};
/*
* trigger event.
* Every listenner have their associated function executed
*
* @param {String} eventName - the event name
* @param {Array}j - argument that will be passed to the exectued function.
*/
eventManager.prototype.trigger = function (eventName, args) {
for (var listener in this.registered[eventName]) {
var l = this.registered[eventName][listener];

@ -1,14 +1,9 @@
'use strict';
var EventManager = require('./eventManager');
module.exports = {
extend: function (destination, source) {
for (var property in source) {
destination[property] = source[property];
}
},
makeEventCapable: function (destination) {
destination.event = new EventManager();
}
};

@ -6,10 +6,10 @@ var EthJSTX = require('ethereumjs-tx');
var ethJSABI = require('ethereumjs-abi');
var EthJSBlock = require('ethereumjs-block');
var BN = ethJSUtil.BN;
var util = require('./lib/util');
var EventManager = require('./lib/eventManager');
function UniversalDApp (executionContext, options, txdebugger) {
util.makeEventCapable(this);
this.event = new EventManager();
var self = this;
self.options = options || {};

Loading…
Cancel
Save