How to use virtual-dom - 10 common examples

To help you get started, we’ve selected a few virtual-dom examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mapillary / mapillary-js / src / component / NavigationComponent.ts View on Github external
private _createVNode(direction: EdgeDirection, name: string): vd.VNode {
        return vd.h(
            `span.Direction.Direction${name}`,
            {
                onclick: (ev: Event): void => {
                    this._navigator.moveDir$(direction)
                        .subscribe(
                            (node: Node): void => { return; },
                            (error: Error): void => { console.error(error); });
                },
            },
            []);
    }
}
github LivelyKernel / lively.next / text2 / rendering.js View on Github external
render() {
    if (this.rendered) return this.rendered;
    let { chunks, height, width } = this;
    height += "px";
    return this.rendered = h("div",
      {style: {height, lineHeight: height}},
     chunks.map(ea => ea.render()));
  }
}
github Aedron / Muse / lib / dom / index.ts View on Github external
function jsx2vTree(jsxTree) {
    if (typeof jsxTree !== 'object') return jsxTree;
    let { elementName, attributes, children } = jsxTree;
    if (children) {
        let index = children.findIndex(c => Array.isArray(c));
        while (index !== -1) {
            children = children.slice(0, index).concat(
                children[index],
                children.slice(index + 1, children.length)
            );
            index = children.findIndex(c => Array.isArray(c));
        }
        children = children.map(c => jsx2vTree(c));
    }
    return h(elementName, handleAttr(attributes), children)
}
github LivelyKernel / lively.morphic / rendering / renderer.js View on Github external
function specTo_h_svg(spec) {
      let {tagName, id, children, style} = spec,
          childNodes = children ? children.map(specTo_h_svg) : undefined;
      if (id) id = path.id + "-" + id;
      return h(tagName, {
        namespace: svgNs,
        id, style,
        attributes: obj.dissoc(spec, ["tagName", "id", "children", "style"])
      }, childNodes);
    }
  }
github rolandpoulter / mach-react / src / virtualDOM.js View on Github external
export function create(type, props, children, context) {
  let definition;
  props = fixProps(props || {});
  if (typeof type === 'string') {
    if (props.cssSelector) type += cssSelector;
    definition = h(type, props, children);
    definition.context = context;
  }
  else {
    definition = new ComponentThunk(type, props, children, context);
  }
  return definition;
}
github LivelyKernel / lively.next / text2 / rendering.js View on Github external
function renderMarkerPart(textLayouter, morph, start, end, style) {
  var padding = morph.padding,
      {x,y} = textLayouter.boundsFor(morph, start),
      {height, x: endX} = textLayouter.boundsFor(morph, end);
  return h("div.marker-layer-part", {
    style: {
      zIndex: -4,
      ...style,
      position: "absolute",
      left: padding.left()+x + "px", top: padding.top()+y + "px",
      height: height + "px",
      width: endX-x + "px"
    }
  });
}
github megamsys / nilavu / app / assets / javascripts / nilavu / widgets / post.js.es6 View on Github external
html(attrs, state) {
        const event_occurred_at = attrs.created_at;
        const event_id = attrs.id;
        const desc = attrs.data.filter((f) => f.key == 'description');
        const status = attrs.data.filter((f) => f.key == 'status');
        const rows = [h("h4", status.get('firstObject').value + " - " + desc.get('firstObject').value)];
        rows.push( h('i', { className: 'circle-' + status.get('firstObject').value + " " + 'pull-right' }));
        const createdAt = new Date(attrs.created_at);
        if (createdAt) {
            rows.push(h('h5.post-date', {}, dateNode(createdAt)));
        }

        return rows;
    }
});
github mapillary / mapillary-js / src / component / CoverComponent.ts View on Github external
private _getCoverBackgroundVNode(conf: ICoverConfiguration): vd.VNode {
        let url: string = conf.src != null ?
            `url(${conf.src})` :
            `url(https://d1cuyjsrcm0gby.cloudfront.net/${conf.key}/thumb-640.jpg)`;

        let properties: vd.createProperties = { style: { backgroundImage: url } };

        let children: vd.VNode[] = [];
        if (conf.loading) {
            children.push(vd.h("div.Spinner", {}, []));
        }

        children.push(vd.h("div.CoverBackgroundGradient", {}, []));

        return vd.h("div.CoverBackground", properties, children);
    }
}
github mapillary / mapillary-js / src / component / CoverComponent.ts View on Github external
private _getCoverBackgroundVNode(conf: ICoverConfiguration): vd.VNode {
        let url: string = conf.src != null ?
            conf.src : Urls.thumbnail(conf.key, ImageSize.Size640);

        let properties: vd.createProperties = { style: { backgroundImage: `url(${url})` } };

        let children: vd.VNode[] = [];
        if (conf.state === CoverState.Loading) {
            children.push(vd.h("div.Spinner", {}, []));
        }

        return vd.h("div.CoverBackground", properties, children);
    }
}
github discourse / discourse / app / assets / javascripts / discourse / widgets / post-admin-menu.js.es6 View on Github external
html() {
    const contents = [];
    contents.push(h("h3", I18n.t("admin_title")));

    buildManageButtons(this.attrs, this.currentUser, this.siteSettings).forEach(
      b => {
        b.secondaryAction = "closeAdminMenu";
        contents.push(this.attach("post-admin-menu-button", b));
      }
    );

    return contents;
  },

virtual-dom

A batched diff-based DOM rendering strategy

MIT
Latest version published 9 years ago

Package Health Score

56 / 100
Full package analysis

Popular virtual-dom functions