Coder Social home page Coder Social logo

Comments (4)

chrisrzhou avatar chrisrzhou commented on May 16, 2024 2

I'll take a jab at this idea and see if it can be made configurable and maybe share some ideas back later!

I see potential in https://github.com/justin-schroeder/arrow-js/blob/master/src/html.ts#L400 as a way to override h (i.e. document.createElement). However html is DOM-based, so more changes might be needed. But the main idea is to decouple DOM-based logic in html into configurable methods that consumers can provide while letting arrow-js keep to its current logic and behaviors.

I don't think this is simple to do, and not suggesting any changes. Mostly just curious if such a configuration makes sense, which may enable adoption in the JS community via:

  • to allow integrations with arrow-js
  • prefer arrow-js or lit ES6 template syntax more than frameworks using transpilation. In a sense if custom h is supported, users can utilize arrow-js.html to author markup, further bringing the community closer to it and lit.
  • support SSR
  • improve migration paths from other frameworks.

from arrow-js.

justin-schroeder avatar justin-schroeder commented on May 16, 2024

Great question — and fundamentally the answer is no, but with all things — it depends. Some important things to note:

  • Arrow does not use a virtual DOM and is fundamentally incompatible with the Virtual DOM concept.
  • Arrow uses fine-grained reactivity to only transform things that need to be reactive.

To be fair these points are not very well spelled out, and the currently published code base is "experimental" in that its a first pass at the concept so some of the benefits (performance) of this approach are not yet realized (has moderate performance rather than blazing fast performance 😂).

That said, it would be possible to decompose html blocks into h function calls, but I’m not sure it provides any significant benefit? Would love to understand the pros of this approach more before make any judgement on it. What use cases can you think of? As for architecture I do believe future versions will include additional hooks for the kinds of extensions you’re describing.

from arrow-js.

chrisrzhou avatar chrisrzhou commented on May 16, 2024

Hey @justin-schroeder, thanks for your prompt reply.

The motivation here is to see if arrow-js can offer a feature while taking one less opinionated behavior (i.e. "always using document.createElement to create nodes):

arrow-js accepts a custom hyperscript-compatible function on initialization (document.createElement by default).
The default behavior renders to DOM (current arrow-js behavior), but one can provide a custom h and basically benefit from arrow-js.html as a templating engine, without modification to the features and API e.g. do not support any form of VDOM.

I'm not sure how this would entirely work, but one might provide the possible values of h:

  • React.createElement: which manages a VDOM tree that React eventually renders. In fact this promotes non-JSX/non-transpile development flow of React as JSX is technically optionally (it's just a DX feature), since everything is using React.createElement under the hood.
  • MyCustomCreateElement: which does custom things e.g. I can write a h method that just assembles a JSON tree for testing/debugging.

I want to stress I'm not proposing any changes to arrow-js's API, but was wondering if it is possible to abstract h (with document.createElement as the default value) to configure arrow-js. This might open the doors to migration from other frameworks.

Example of how it "may" work?

import { configure } from 'arrow-js';

configure({h: document.createElement}); // no need to configure but stating as an example
configure({
  h: React.createElement,
  mapHtmlProps,
}); // provide a custom createElement and `mapProps`

const mapHtmlProps = { // gives a chance to map from the consumer interface to arrow-js/lit's `html`
  click: 'onClick',
  class: 'className',
}

html`<button @click="${() => console.log('clicked')}"`

// evaluates to React.createElement('button', { onClick: () => console.log('clicked') }); etc

Motivation for this question comes from my personal exploration on creating framework-agnostic style/theming libraries i.e. uinix-ui which works in any h-friendly library (e.g. React, Preact, Solid, Mithril, htm etc), so the motivation derives from there.

from arrow-js.

bbqbaron avatar bbqbaron commented on May 16, 2024

What use cases can you think of?

For my part, it's that editing normal functions is much easier than editing embedded string literals. Arrow is so stripped down (which is great) that it seems like an odd requirement for me to find custom IDE tooling to get autocomplete, shortcuts, linting, etc.

from arrow-js.

Related Issues (20)

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.