question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

thoughts on extensible custom tags

See original GitHub issue

So this may not be in the philosophy of bel, but how/should/can I easily 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 bel`<button>my ${opts.name} button</button>`
}

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

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

// which is actually just

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

// or

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

// which is actually

const customtagsuse2 = bel`<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 bel.

so something like:

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

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

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
shamacommented, Apr 19, 2016

@SilentCicero webpack can run browserify transforms too.

But what about intercepting the actual yo or bel elements and doing it there, does that seem unfeasible or very difficult to accomplish on that level?

When parsing the template literal, it doesn’t know about the variables on the same scope of the literal, only the expressions passed in with ${}. So it would require registering each component as the above examples are doing and informing the parser about that registry, which can get pretty messy.

0reactions
timwiscommented, Jun 17, 2016

Hey guys, was thinking about this today and had a similar idea… what about using proper custom elements from the web components spec?

EDIT: Probably no matter what you do, the issue of passing in attributes other than strings will be annoying, ie. <MyElement codes=${ [ 'foo', 'bar' ] }></MyElement>

EDIT2: Threw together an example using choo

Read more comments on GitHub >

github_iconTop Results From Across the Web

U.S. GAAP – XBRL Custom Tags Trend - SEC.gov
“From 2019 to 2020, custom tag rates changed from 16% to 20%. The analysis for Forms 10-K and 10-K/A shows a decrease in...
Read more >
Defining custom tags using hiccup ? - Google Groups
Hi, I like the way hiccup allows you to represent html elements as datastructure. However this is limited to native elements.
Read more >
An extensible ExifReader class with customizable tag handlers
An ExifReader class in C# that supports custom formatting and extraction. StyleCop compliant code, with demos for WPF and Windows Forms.
Read more >
How to create customizable Liquid tags in Jekyll - sverrirs.blog
This is the definite guide to show you how to create flexible and fully customizable Liquid code tags to use in Jekyll static...
Read more >
Extensible Enumerations A Guide for Preparers - FASB
any party responsible for tagging information in an SEC Extensible Business ... Extensible Enumeration elements are a custom datatype, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found