max-mapper / yo-yo

A tiny library for building modular UI components using DOM diffing and ES6 tagged template literals

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

custom elements

SilentCicero opened this issue · comments

commented

note, I posted this question to the bel issues as well.

So this may not be in the philosophy of bel/yoyo, but how/should/can I create an extensible module for bel/yoyo (the module I use) that allows for custom tags/props that just render functions.

Here is what I'm thinking:

const Button = function (opts) {
    return yo`<button>my ${opts.name} button</button>`
}

const customtagsuse = yo`<div><Button name="Nick" /></div>`

// which is actually just

const customtagsuse = yo`<div>${Button({name: "Nick"})}</div>`

// or

const Col = function (_yield, opts) {
   return yo`<div class="column">${_yield}</div>`
}

const customtagsuse2 = yo`<div><Col> some cols </Col></div>`

// which is actually

const customtagsuse2 = yo`<div>${Col(" some cols ")}</div>`

Kinda reactish, but all it's doing is regexing the string, and replacing it with the element.

I'm thinking of providing a layer to yo/bel.

so something like:

var extensible = require("bel-custom")
var yo = extensible(require("yo"))
yo.customElements = {"Button": Button}; // sort of thing

Any thoughts on design patterns, approaches, potential pitfalls, potential benefits?

Closing as the conversation has moved in choojs/nanohtml#25