dyo / dyo

Dyo is a JavaScript library for building user interfaces.

Home Page:https://dyo.js.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Difference regarding "createElement" between dio.js and Dyo

mcjazzyfunky opened this issue · comments

This is about a minor important feature:

In case you were using some kind of legacy system (some special CMS, a webshop backend system or whatever) where you could add HTML and JavaScript to your content but you did not have some kind of build/transpiler support and you had to use h/createElement directly without JSX , then it was quite useful that for the createElement function in "dio.js" the second argument props was optional. Something like this was working:

const content =
  h('div',
    h('h3', 'Headline'),
    h('p', 'Some content'))

In Dyo this is not supported any longer.
Any opinions whether this "optional props argument for createElement" feature could be reintroduced again in some future Dyo version?

PS: Dyo is currently only checking for "is object" - would also need to check for "is valid element", "is iterable object" and "is thenable" . [Edit - a bit later] Mmmh, "is thenable" may be a bit problematic, as you cannot distinguish between a "real" thenable and a props object that contains by coincidence a key named then whose value is a function (instanceof Promise would be easier, but cannot be used here, of course)

It is possible for example.

// now
typeof props === 'object' && props !== null 
// after
props instanceof Object 

Which would conveniently(because dyo vnode objects don't inherit from the Object constructor) handle all but the non-promise-contructor thenables cases mentioned.

The above however wouldn't catch Promises and Arrays that inherit from Object.

The props instanceof Object would serve to allow the example you posted but not:

const content = h('div', [
    h('h3', 'Headline'),
    h('p', 'Some content')
])

Might still very well be worth it for the ergonomics, given the more common nature of the former.

@thysultan
Not really sure whether this change request has been implemented or the issue has just been closed as this shall not be implemented.
In the first case I'd like to inform you that this is not working:
https://codesandbox.io/s/gallant-night-qvj2n

patched in 2.0.1