UNPKG

hyperhtml

Version:

A Fast & Light Virtual DOM Alternative

40 lines (34 loc) 1 kB
const attributes = {}; const intents = {}; const keys = []; const hasOwnProperty = intents.hasOwnProperty; let length = 0; export 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); } } } };