-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplus.js
More file actions
49 lines (44 loc) · 1.25 KB
/
plus.js
File metadata and controls
49 lines (44 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// start patch for lighterhtml-plus
import CustomEvent from '@ungap/custom-event';
import WeakMap from '@ungap/weakmap';
import attributechanged from 'attributechanged';
import disconnected from 'disconnected';
const CONNECTED = 'connected';
const DISCONNECTED = 'dis' + CONNECTED;
const poly = {
Event: CustomEvent,
WeakSet: (typeof WeakSet == typeof add ?
WeakSet :
function () {
const ws = new WeakMap;
ws.add = add;
return ws;
}
)
};
const observe = disconnected(poly);
const attrChanged = attributechanged(poly);
// substitute of uhandlers event
const event = (node, name) => {
let oldValue;
let type = name.slice(2);
if (type === CONNECTED || type === DISCONNECTED)
observe(node);
else if (type === 'attributechanged')
attrChanged(node);
else if (!(name in node) && name.toLowerCase() in node)
type = type.toLowerCase();
return newValue => {
const info = isArray(newValue) ? newValue : [newValue, false];
if (oldValue !== info[0]) {
if (oldValue)
node.removeEventListener(type, oldValue, info[1]);
if (oldValue = info[0])
node.addEventListener(type, oldValue, info[1]);
}
};
};
function add(key) {
return this.set(key, true);
}
// end patch for lighterhtml-plus