Skip to content
This repository has been archived by the owner on Jul 30, 2018. It is now read-only.

Latest commit

 

History

History
65 lines (44 loc) · 1.24 KB

on.md

File metadata and controls

65 lines (44 loc) · 1.24 KB

On

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

emit

Dispatch event to target.

import { emit } from '@dojo/core/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 '@dojo/core/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 '@dojo/core/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 '@dojo/core/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