virtualstate / x

Bring your own JavaScript tooling.
https://virtualstate.dev
MIT License
23 stars 0 forks source link

equals #13

Open fabiancook opened 2 years ago

fabiancook commented 2 years ago

🚀 Feature Proposal

Compare and return true or false if two vnode structures are equal

Motivation

To be able to compare structures

Example

let a = (
  <container>
    <inner />
  </container>
)

function *A() {
  yield <container />
  yield <container><inner loading={true} /></container>
  yield <container><inner /></container>
}
if (await equal(a, <A />)) {
   // ???
}
fabiancook commented 2 years ago

The initial implementation of this function is available here:

https://github.com/virtualstate/x/blob/6db6e3c2038727307aab6a8b5efb82498019fbcb/packages/fringe/src/equal.ts#L13

It is marked as experimental.

It will do a direct compare of the final yielded children of each node, with its relevant paired node in the same position of the vnode structure.

Only nodes that have a source reference source (string | number | ...) are compared, and only options with source reference values are compered.