Git Product home page Git Product logo

rdom's Introduction

  • ๐Ÿ‘‹ Hi, Iโ€™m @aalin
  • ๐Ÿ‘€ Iโ€™m interested in graphics, music, web technologies
  • ๐ŸŒฑ Iโ€™m currently learning reactive programming
  • ๐Ÿ’ž๏ธ Iโ€™m looking to collaborate on mayu live, which is a server side VDOM framework written in Ruby.
  • If you like what I'm trying to do, please consider supporting me on Open Collective, or buy me a coffee.
  • ๐Ÿ“ซ How to reach me, send an email to the email address I use for commits.

rdom's People

Contributors

aalin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

rdom's Issues

Load custom elements asynchronously and use `CustomElementRegistry.whenDefined()`

So for each element, generate /.rdom/BxI-H0gjVsQV9oRAejuH.html with the following contents:

<style>@import url(XCpQkoNvHXVvo8F_EUn3.css);</style>
<div><h3><slot name="s0"></slot></h3><p><slot name="s1"></slot></p></div>

And then, Patches.DefineCustomElement() would just fetch that file.. and then there should be some logic to defer some calls until the element has been defined, using CustomElementRegistry.whenDefined()... We can't assign slots or callbacks until the element has been defined and connected... but we can still create all the DOM structures we need.

Something like this maybe:

const Patches = {
  /* ... */
  async DefineCustomElement(name, src) {
    const template = createTemplate(await fetchHTML(src))
    customElements.define(
      name,
      class extends RDOMElement { static template = template }
    )
  },
  AssignSlot(id, name, ids) {
    whenDefined(this.nodes.get(id), (node) => {
      node.assignSlot(
        name,
        ids.map((id) => this.nodes.get(id)).filter(Boolean)
      )
    })
  },
  /* ... */
}

function whenDefined(node, cb) {
  if (node instanceof RDOMElement) {
    return cb(node)
  }

  if (node instanceof HTMLElement) {
    if (node.tagName.startWith("RDOM-")) throw "not an rdom element"
    return customElements.whenDefined(node.name).then(() => cb(node))
  }
}

There are some ideas here too:
https://shoelace.style/getting-started/usage?id=waiting-for-components-to-load

When a component renders, it could also specify which custom elements it depends on, and it could be invisible until all elements have been loaded.

The benefit of doing this is caching. If different components have the same markup, it would become one custom element, and they would be cached... so any markup will only load once on the first load and then whenever you revisit a page the markup will be cached.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.