class Event
{
	constructor(name)
	{
		console.log("new event: " + name);
		this.name = name;
		this.listeners = [];

	}

	register(module)
	{
		this.listeners.push(module);
	}

	dispatch()
	{
		var n = this.name;

		this.listeners.forEach(function(el)
		{
			el.callback(n, "test_parameter");
		})
	}
}

class Hub
{
	constructor()
	{
		this.events = {
					'#clock': new Event('#clock'),
					'#focus1': new Event('#focus1'),
					'#focus2': new Event('#focus2')
		};
	}

	test()
	{
		console.log('ok');
	}

	register(name, module)
	{
		this.events[name].register(module);
	}

	create(name)
	{
		this.events[name] = new Event(name);
	}

	dispatch(name)
	{
		this.events[name].dispatch();
	}
}



let EventManager = new Hub();





class FakePluggin
{
	constructor(domTarget)
	{
		this.domTarget = domTarget;
	}

	register(eventName, callback)
	{
		EventManager.register(eventName, { 'callback': callback.bind(this) });
	}
}

function dummyCallback(eventName, eventParameter1)
{
	this.domTarget.appendChild(document.createTextNode('New event "' + eventName + '" [ ' + eventParameter1 + ' ]'));
	this.domTarget.appendChild(document.createElement('br'));
}

function anotherDummyCallback(eventName, eventParameter1)
{
	this.domTarget.appendChild(document.createTextNode('Another new event "' + eventName + '" [ ' + eventParameter1 + ' ]'));
	this.domTarget.appendChild(document.createElement('br'));
}

function focusCallback(eventName, eventParameter1)
{
	this.domTarget.appendChild(document.createTextNode('Sibling received a focus event'));
	this.domTarget.appendChild(document.createElement('br'));
}

var pluggin1 = new FakePluggin(document.querySelector('#div_1_1'));
var pluggin2 = new FakePluggin(document.querySelector('#div_1_2'));


//EventManager.createEvent('#clock');
pluggin1.register('#clock', dummyCallback);
pluggin2.register('#clock', anotherDummyCallback);
pluggin1.register('#focus2', focusCallback);
pluggin2.register('#focus1', focusCallback);

setInterval(function(){
	EventManager.dispatch('#clock');
}, 5000);

@@ -20,24 +20,32 @@
 tructor(name
+, params
 )%0A%09%7B%0A%09%09conso
@@ -117,16 +117,39 @@
 s = %5B%5D;%0A
+%09%09this.params = params;
 %0A%09%7D%0A%0A%09re
@@ -211,16 +211,22 @@
 ispatch(
+params
 )%0A%09%7B%0A%09%09v
@@ -242,16 +242,288 @@
 is.name;
+%0A%09%09var params_send = %7B%7D;%0A%0A%09%09/*for (var i in this.params)%0A%09%09%7B%0A%09%09%09if (!params.hasOwnProperty(this.params%5Bi%5D))%0A%09%09%09%7B%0A%09%09%09%09console.error('missing parameters ' + this.params%5Bi%5D + ' for event ' + n);%0A%09%09%09%09return ;%0A%09%09%09%7D%0A%09%09%09params_send%5Bthis.params%5Bi%5D%5D = params%5Bthis.params%5Bi%5D%5D;%0A%09%09%7D*/
 %0A%0A%09%09this
@@ -580,24 +580,14 @@
 (n, 
-%22test_parameter%22
+params
 );%0A%09
@@ -655,151 +655,142 @@
 %09%09'#
-clock': new Event('#clock'),%0A%09%09%09%09%09'#focus1': new Event('#focus1'),%0A%09%09%09%09%09'#focus2': new Event('#focus2')%0A%09%09%7D;%0A%09%7D%0A%0A%09test()%0A%09%7B%0A%09%09console.log('ok')
+APIRequestFileOpen': new Event('#APIRequestFileOpen', %5B'file'%5D),%0A%09%09%09%09%09'#OnFileOpen': new Event('#OnFileOpen', %5B'file', 'content'%5D)%0A%09%09%7D
 ;%0A%09%7D
@@ -930,24 +930,32 @@
 ispatch(name
+, params
 )%0A%09%7B%0A%09%09this.
@@ -976,16 +976,22 @@
 ispatch(
+params
 );%0A%09%7D%0A%7D%0A
@@ -1027,16 +1027,18 @@
 ();%0A%0A%0A%0A%0A
+/*
 %0Aclass F
@@ -2221,53 +2221,8 @@
 ck);
-%0Apluggin2.register('#focus1', focusCallback);
 %0A%0Ase
@@ -2286,9 +2286,11 @@
 , 5000);
+*/
 %0A

edit hub to accept parameters