uhtml
Version:
A micro HTML/SVG render
48 lines (42 loc) • 1.51 kB
JavaScript
'use strict';
const _type = Symbol('type');
const _bubbles = Symbol('bubbles');
const _cancelable = Symbol('cancelable');
const _defaultPrevented = Symbol('defaultPrevented');
const _target = Symbol('target');
exports._target = _target;
const _currentTarget = Symbol('currentTarget');
exports._currentTarget = _currentTarget;
const _stoppedPropagation = Symbol('stoppedPropagation');
exports._stoppedPropagation = _stoppedPropagation;
const _stoppedImmediatePropagation = Symbol('stoppedImmediatePropagation');
exports._stoppedImmediatePropagation = _stoppedImmediatePropagation;
module.exports = class Event {
constructor(type, { bubbles = false, cancelable = false } = {}) {
this[_type] = type;
this[_bubbles] = bubbles;
this[_cancelable] = cancelable;
this[_target] = null;
this[_currentTarget] = null;
this[_defaultPrevented] = false;
this[_stoppedPropagation] = false;
this[_stoppedImmediatePropagation] = false;
}
get type() { return this[_type]; }
get bubbles() { return this[_bubbles]; }
get cancelable() { return this[_cancelable]; }
get target() { return this[_target]; }
get currentTarget() { return this[_currentTarget]; }
get defaultPrevented() { return this[_defaultPrevented]; }
preventDefault() {
if (this[_cancelable])
this[_defaultPrevented] = true;
}
stopPropagation() {
this[_stoppedPropagation] = true;
}
stopImmediatePropagation() {
this.stopPropagation();
this[_stoppedImmediatePropagation] = true;
}
}