ohanhi / elm-native-ui

[CLOSED] Experiment: mobile apps in Elm using React Native.
BSD 3-Clause "New" or "Revised" License
1.54k stars 76 forks source link

Use virtual-dom instead of VTree #22

Closed yusefnapora closed 8 years ago

yusefnapora commented 8 years ago

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 :)

ohanhi commented 8 years ago

Closing in favor of #24