Example #1
0
export function define(tagName, Component, config = {}) {
    registry.define(tagName, Component, config);
    let opts = {
        prototype: Component.prototype,
    };
    if (config.extends) {
        opts.extends = config.extends;
    }
    return document.registerElement(tagName, opts);
}
Example #2
0
 [].forEach.call(nodes, (node) => {
     if (!DOM.getNodeComponent(node)) {
         let Ctr = registry.get(node.getAttribute('is') || node.tagName);
         if (Ctr) {
             let elem = new Ctr();
             elem.node = node;
             DOM.connect(elem);
         }
     } else {
         DOM.connect(node);
     }
     if (node.children) {
         onCreation(node.children);
     }
 });
Example #3
0
File: shim.js Project: Chialab/dna
 constructor() {
     if (!isNew(this)) {
         return this;
     }
     let desc = registry.get(this.is, true);
     let config = desc.config;
     // Find the tagname of the constructor and create a new element with it
     let element = document.createElement(
         config.extends ? config.extends : desc.is
     );
     element.__proto__ = desc.Ctr.prototype;
     if (config.extends) {
         element.setAttribute('is', desc.is);
     }
     return element;
 }
Example #4
0
File: idom.js Project: Chialab/dna
    return () => {
        if (!isObject(props)) {
            if (props) {
                children.unshift(props);
            }
            props = {};
        }
        let key = props.key;
        delete props.key;

        const Component = registry.get(props.is || element);
        elementOpenStart(element, key);

        for (let k in props) {
            let val = props[k];
            if (!isFalsy(val) && (!Component || isString(val) || !isNaN(val) || val === true)) {
                attr(k, val);
            }
        }

        const node = elementOpenEnd(element);
        const component = Component && (DOM.getNodeComponent(node) || new Component(node));

        if (component && children.length === 0) {
            skip();
        } else {
            handleChildren(children, node);
        }
        elementClose(element);

        if (component && isObject(component.properties)) {
            patch.current.after(() => {
                let componentProperties = component.properties;
                for (let k in props) {
                    if (componentProperties.hasOwnProperty(k)) {
                        component[k] = props[k];
                    }
                }
            });
        }

        return node;
    };