Skip to content

VNode.children should allow more range.  #17

@fabiancook

Description

@fabiancook

🚀 Feature Proposal

Update the type signature of VNode to

type VNodeChild = string | number | boolean | undefined | VNode | Iterable<VNodeChild>;

interface VNodeChildrenContainer {
  children: AsyncIterable<VNodeChild> | Iterable<VNodeChild>
}

This opens up compatibility, an introduces "scalar" values as immediately represented values with no abstraction.

I believe this would also reduce the requirement to understand why we might want to wrap these (which was only to maintain a type definition, which may be easier to do now!)

Motivation

Currently children is transformed to maintain a consistent reading pattern, if read functions are provided through #16 there is less of a reason to enforce that children must be wrapped nodes for no gain.

Example

const node = {
  children: [1, 2, "hello", { children: [ 3, 4, ] }, [ 5, 6 ] ]
}
const node = {
  children: {
    async *[Symbol.asyncIterator]() {
      yield 1;
      yield "hello";
      yield [1, 2, "hello", { children: [ 3, 4, ] }, [ 5, 6 ] ];
   } 
  }
}

These native representations should require zero transformation from the implementation of @virtualstate/fringe, and instead now can be directly read using read functions instead.

Read functions should include a function that creates a consistent node with a strict type, however it should not be needed in the majority of cases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions