GithubHelp home page GithubHelp logo

Children as data? about solid HOT 4 CLOSED

bluenote10 avatar bluenote10 commented on May 5, 2024
Children as data?

from solid.

Comments (4)

ryansolid avatar ryansolid commented on May 5, 2024

It won't convert a single expression to a Document Fragment. I do it to shortcut what I consider the common case. Originally I had the children as arrays but an array of nodes is less efficient as far as my benchmarking shows. I wondered about this precise case but since I had never actually hit it ever using React and the benefits for shortcutting the renderer beneficial I went that way. The main reason is I create nodes by cloning templates. An array would take an otherwise singular template and split it into multiple templates that'd all be cloned separately.

Consider:

<MyComponent>
  <div>Hello</div>
  <div>World</div>
</MyComponent>

With a change to get the single node effect I would need to write it as:

<MyComponent>{
  <>
    <div>Hello</div>
    <div>World</div>
  </>
}</MyComponent>

Whereas for the Data Array you can just currently write:

<MyComponent>{
  [1, 2, 3]
}</MyComponent>

I'm not sure there is any case that needs multiple expression children to pass data. It's sort of pure overhead.

It's quite possible the types are incorrect. I am yet to use the JSX types in a project and I made the change to the child operation around the same time the types were contributed. What should be happening is any single expression is left untouched to handle (passing data, render props etc) and anything with multiple children is made into a document fragment. That way children is always a single non-array value (unless you pass an array), that can be either used directly or appended to the DOM without further consideration.

from solid.

bluenote10 avatar bluenote10 commented on May 5, 2024

👍 the single array argument example solves this use case in my opinion.

The only question is if fixing the types is actually possible. It might be part of the JSX language specs requiring that multiple arguments become an array. Even if it's not possible to fix the type it might be enough to just document it as a small deviation from the JSX specs (with a hint that type casts are required in TS).

from solid.

ryansolid avatar ryansolid commented on May 5, 2024

We do set up our own types so maybe there is something to be done there?

https://github.com/ryansolid/babel-plugin-jsx-dom-expressions/blob/master/types/index.d.ts

Is it that these types only extend to Intrinsic Elements? And not Custom Elements? I guess this is my TypeScript issue of the week. Can't seem to go a week without finding some new fun surprise.

Help would be very much appreciated to know whether there is a TypeScript solution for this.

from solid.

ryansolid avatar ryansolid commented on May 5, 2024

microsoft/TypeScript#30918 is sort of the opposite issue. Looks like TypeScript won't play ball. I've updated documentation. Seems like that is all I can do.

from solid.

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.