I'm not sure this is actually a practical idea, but I spent some time looking into making main work this week, inspired by this discussion linked to from the readme.
The elm compiler enforces that the return type of main be either Element, VirtualDom.Node (aka Html) or a signal of either of the above.
In theory you could overwrite the Native.VirtualDom.node function and replace it with whatever you want, or you could define a new function that claims to return a VirtualDom.Node but actually calls out to Native.ReactNative.node (or something).
But I'm not sure that it's actually necessary to replace the VirtualDom node type at all. virtual-dom nodes are already similar enough to the VTree in this project that you could probably just use them directly.
Replacing the render and updateAndReplace functions from the virtual-dom package would probably look very similar to the vtreeToReactElement function you've already defined.
One thing I discovered when poking at this is that, out of the box, React Native will blow up if you include the virtual-dom package. This is because the elm virtual-dom wrapper is built with browserify, which defines a function named require. This confuses the RN packager, which will try to use its own require function instead. If you globally replace require with e.g. _require in the compiled elm.js, it will load fine.
Anyway, I'm hoping to have more time to muck about with this soon, but I'm curious to see what you think. Nice work so far, btw :)
I'm not sure this is actually a practical idea, but I spent some time looking into making
main
work this week, inspired by this discussion linked to from the readme.The elm compiler enforces that the return type of
main
be eitherElement
,VirtualDom.Node
(akaHtml
) or a signal of either of the above.In theory you could overwrite the
Native.VirtualDom.node
function and replace it with whatever you want, or you could define a new function that claims to return aVirtualDom.Node
but actually calls out toNative.ReactNative.node
(or something).But I'm not sure that it's actually necessary to replace the VirtualDom node type at all.
virtual-dom
nodes are already similar enough to theVTree
in this project that you could probably just use them directly.Replacing the
render
andupdateAndReplace
functions from the virtual-dom package would probably look very similar to thevtreeToReactElement
function you've already defined.One thing I discovered when poking at this is that, out of the box, React Native will blow up if you include the
virtual-dom
package. This is because the elm virtual-dom wrapper is built with browserify, which defines a function namedrequire
. This confuses the RN packager, which will try to use its ownrequire
function instead. If you globally replacerequire
with e.g._require
in the compiledelm.js
, it will load fine.Anyway, I'm hoping to have more time to muck about with this soon, but I'm curious to see what you think. Nice work so far, btw :)