xialvjun/preact-flyd

Bug when stream can emit nulls

theadam opened this issue · 2 comments

I've changed the ReactiveClass render method with:
return children instanceof VNode ? h(children.nodeName, {...children.attributes, props}, ...children.children) : children....
That should work, and in fact, it indeed works on the new counter example ({ count$.map(c => c % 2 === 1 ? c+'' : null) }), but it doesn't work on the map_to_a_list$ example... That's weird.....
I doubt if it's preact's bug...... Or if only there are more documents on preact.

Well, a stream can emit everything at every time, but self control element just want a valid element (preact can accept a string, but react just accept a valid element... )

If I remove self control element and all is parent control element, then it will consume some more.

And since children is just a prop of props, but I change the total children to a stream just because one of the children is a stream, then should I change the total of a prop to a stream just because some inner prop of the prop is a stream? ... I don't know...

Maybe the best way is just remove the concept of self control element, and tell people be aware of the consume of parent control element with more document...

function wrapChildren(children) {
  const streamElement$s = children.filter(child => isStream(child))
  if (streamElement$s.length > 0) {
    return combine(() => {
      return children.map(child => {
        if (!isStream(child)) {
          return child
        }
        if (streamElement$s.indexOf(child) > -1) {
          return child()
        }
        return preactH(reactive(), {children$: child})
      })
    }, streamElement$s)
  }
  return children
}

I really don't know which is the best... Hoping at some time, the react like library can return some more type like string, array, null...