-
-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathIntent.js
More file actions
40 lines (35 loc) · 1.05 KB
/
Intent.js
File metadata and controls
40 lines (35 loc) · 1.05 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
'use strict';
const attributes = {};
const intents = {};
const keys = [];
const hasOwnProperty = intents.hasOwnProperty;
let length = 0;
Object.defineProperty(exports, '__esModule', {value: true}).default = {
// used to invoke right away hyper:attributes
attributes,
// hyperHTML.define('intent', (object, update) => {...})
// can be used to define a third parts update mechanism
// when every other known mechanism failed.
// hyper.define('user', info => info.name);
// hyper(node)`<p>${{user}}</p>`;
define: (intent, callback) => {
if (intent.indexOf('-') < 0) {
if (!(intent in intents)) {
length = keys.push(intent);
}
intents[intent] = callback;
} else {
attributes[intent] = callback;
}
},
// this method is used internally as last resort
// to retrieve a value out of an object
invoke: (object, callback) => {
for (let i = 0; i < length; i++) {
let key = keys[i];
if (hasOwnProperty.call(object, key)) {
return intents[key](object[key], callback);
}
}
}
};