How to use metal-events - 10 common examples

To help you get started, we’ve selected a few metal-events examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github metal / metal.js / test / DomEventEmitterProxy.js View on Github external
it('should change the element that events are proxied from', function() {
		var origin = document.createElement('div');
		document.body.appendChild(origin);

		var target = new EventEmitter();
		var proxy = new DomEventEmitterProxy(origin, target);

		var listener = sinon.stub();
		target.on('click', listener);

		var origin2 = document.createElement('div');
		document.body.appendChild(origin2);
		proxy.setOriginEmitter(origin2);

		dom.triggerEvent(origin, 'click');
		assert.strictEqual(0, listener.callCount);

		dom.triggerEvent(origin2, 'click');
		assert.strictEqual(1, listener.callCount);
		assert.ok(listener.args[0][0]);
github liferay / senna.js / test / app / App.js View on Github external
it('should not to clear screen cache the being used in a pending navigation', (done) => {
		const event = new EventEmitter();
		class StubScreen extends Screen {
			constructor() {
				super();

				this.cacheable = true;
			}

			flip(surfaces) {
				super.flip(surfaces);
				event.emit('flip');
			}
		}

		const callback = () => {
			this.app.clearScreensCache();
			assert.strictEqual(1, Object.keys(this.app.screens).length);
github metal / metal.js / test / DomEventEmitterProxy.js View on Github external
it('should not proxy event emitter events after disposed', function() {
		var origin = new EventEmitter();
		var target = new EventEmitter();
		var proxy = new DomEventEmitterProxy(origin, target);

		var listener = sinon.stub();
		target.on('event1', listener);

		proxy.dispose();
		origin.emit('event1', 1, 2);
		assert.strictEqual(0, listener.callCount);
	});
github metal / metal-training / playground / examples / EventEmitter / emit.js View on Github external
'use strict';

import EventEmitter from 'metal-events';

const emitter = new EventEmitter();
emitter.on('myEvent', (...args) => console.log(args));
debugger;
emitter.emit('myEvent', 1, 2, 3);
github metal / metal.js / packages / metal-component / src / EventsCollector.js View on Github external
attachListener(eventType, fnNamesString) {
		var selector = '[data-on' + eventType + '="' + fnNamesString + '"]';

		this.hasListener_[selector] = true;

		if (!this.eventHandles_[selector]) {
			this.eventHandles_[selector] = new EventHandler();
			var fnNames = fnNamesString.split(',');
			for (var i = 0; i < fnNames.length; i++) {
				var fn = this.component_.getListenerFn(fnNames[i]);
				if (fn) {
					this.eventHandles_[selector].add(this.component_.delegate(eventType, selector, this.onEvent_.bind(this, fn)));
				}
			}
		}
	}
github metal / metal-training / playground / examples / EventEmitter / many.js View on Github external
'use strict';

import EventEmitter from 'metal-events';

const emitter = new EventEmitter();
debugger;
emitter.many('myEvent', 3, () => {});

emitter.emit('myEvent');
emitter.emit('myEvent');
emitter.emit('myEvent');
github metal / metal-training / playground / examples / EventEmitter / off.js View on Github external
'use strict';

import EventEmitter from 'metal-events';

const emitter = new EventEmitter();
const listener = () => {};
emitter.on('myEvent', listener);

debugger;
emitter.off('myEvent', listener);
emitter.emit('myEvent', 1, 2, 3);
github LiferayCloud / marble / packages / marble-autocomplete / src / AutocompleteBase.js View on Github external
created() {
    this.eventHandler_ = new EventHandler();
    this.on('select', this.select);
  }
github metal / metal.js / packages / metal-component / src / Component.js View on Github external
addListenersFromObj_(obj) {
		if (!this.eventsStateKeyHandler_) {
			this.eventsStateKeyHandler_ = new EventHandler();
		}
		const handles = addListenersFromObj(this, obj);
		this.eventsStateKeyHandler_.add(...handles);
	}

metal-events

Classes responsible for emitting and listening to events

BSD
Latest version published 6 years ago

Package Health Score

57 / 100
Full package analysis