Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support text node among HTMLElements #1

Open
sarimarton opened this issue Jan 25, 2019 · 1 comment
Open

Support text node among HTMLElements #1

sarimarton opened this issue Jan 25, 2019 · 1 comment

Comments

@sarimarton
Copy link

Hi,

Thanks for this awesome lib. It's genius.

One thing is bothering though, namely that I can't use orphan text nodes among HTMLElements.

I have a custom pragma to support JSX, but the following only displays "Clock is", and it seems that there's no easy workaround:

/** @jsx callbagHtmlPragma */
const callbagHtmlPragma = (nodeName, attributes, ...children) =>
  typeof nodeName === 'function'
    ? nodeName(Object.assign({}, attributes, { children }))
    : h[nodeName](
        attributes || {},
        typeof children[0] === 'string' ? children[0] : children
      );
// ...
document.body.appendChild(
  <div>
    <h4>Clock is <em>awesome</em>:</h4>
    <Clock />
  </div>
);
@Risto-Stevcev
Copy link
Owner

Thanks 🙂

Yeah I noticed that a little while ago. I've been working on writing a port of this for bucklescript with some strong typing guarantees, but I needed to separate out the callbags into their own custom elements so that the typing could be sound. So I separated it into two packages, declaredom and callbag-element:

https://github.com/Risto-Stevcev/declaredom/blob/master/index.js
https://github.com/Risto-Stevcev/callbag-element

I've been updating declaredom to include more things but I haven't kept callbag-html in sync. You can use declaredom + callbag-element to get the same kind of functionality, but callbag-html is definitely more convenient than using the custom element if you use vanilla js or typescript.

I think I'll have to make declaredom a dependency and then have it override the setChildren attribute for this library so that it accepts callbags, since that should really the only difference between declaredom and callbag-html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants