Skip to content

Latest commit

 

History

History
53 lines (40 loc) · 1.2 KB

on.md

File metadata and controls

53 lines (40 loc) · 1.2 KB

On

dojo-core/on provides event handling support with methods to attach and emit events.

emit - Dispatch event to target

import { emit } from 'src/on';

var button = document.getElementById('button');
var DOMEventObject = {
	type: 'click',
	bubbles: true,
	cancelable: true
};

emit(button, DOMEventObject);

on - Adds event listener to target.

import { on } from 'src/on';

var button = document.getElementById('button');

on(button, 'click', function (event) {
	console.log(event.target.id);
});

once - Attach an event that can only be called once to a target.

import { once } from 'src/on';

var button = document.getElementById('button');
once(button, 'click', function (event) {
	console.log(event.target.id);
	console.log('this event has been removed')
});

pausable - Attach an event that can be paused to a target.

import { pausable } from 'src/on';

var button = document.getElementById('button');
var buttonClickHandle = pausable(button, 'click', function (event) {
	console.log(event.target.id);
});

buttonClickHandle.pause(); // when paused the event will not fire
buttonClickHandle.resume(); // after resuming the event will begin to fire again if triggered