ViewModel + Inferno


#1

ViewModel now supports Inferno.

For testing purposes I switched an entire app from React to Inferno without changing a single component file. I just changed .babelrc to use Inferno and that’s it.


#2

It’s cool that you keep ViewModel up and running!

How is this possible? Does Inferno has the same syntax as React?


#3

That’s the magic of transpilers. Technically speaking I can make VM work with almost anything. Take this for example:

App({
  message: 'Hello, World!',
  render() {
    <h1 b="text: message" />
  }
})

There’s nothing there that ties you to React so VM can output Inferno compatible code instead. I added Inferno for the lulz because the API is almost identical to React so there wasn’t that much to do.


#4

Wow, that’s really great!
So, basically, you can build a top-level API on top of any renderer?
You could market ViewModel as a universal front-end api! Whaddaya think of that?


#5

I like the idea of VM as a kind of buffer between us and a framework. For example, React is touting a change in the API where the render function will have to return a function in the future. With VM that change wouldn’t affect us at all since we can just change the transpiler plugin. The bad news is that VM is a kind of buffer between us and a framework. If the framework’s API has a breaking change, we can’t upgrade until VM does.


#6

this may be of interest to you for Vue support https://github.com/vueact/babel-plugin-transform-react-to-vue


#7

So how do we use inferno?


#8

https://viewmodel.org/#BasicsInferno

You can get an inferno boilerplate and add VM. Replacing React depends on your setup and how tightly coupled it is with React. I haven’t tried to set it up with Meteor yet.


#9

Thanks Manuel for your continued effort, Viewmodel really is a value-add thingy.
Reactioncommerce is in the progress of switching to a component based API thereby supporting React. Would be interesting to see whether or not it’s possible to plug Viewmodel and Inferno into Reactioncommerce once it’s done.


#10

You can’t mix React and Inferno, it’s one or the other. ViewModel on the other hand can be mixed with either one. VM components traspile to React/Inferno so you can start using VM with an existing project. That also means you can call “normal” React components from VM ones.

Switching an existing app from React to Infero or vice-versa largely depends on the existing setup. Some webpack setups are tightly coupled with React so it takes more work. Converting the components also depend on how they’re written but most should be “greppable”. VM components have the advantage that there’s nothing to change.


#11

Hi Manuel! Thanks for your ongoing work! I really enjoy working with ViewModel+React so far. Makes me smile, as you say…

Are you actually working with Inferno? Are there significant advantages to do so?


#12

I’m glad you’re happy with VM =)

I’m not working with Inferno. I think the safer bet is to continue working with React. I added Inferno more as an experiment than anything else. But by all means if anyone wants to use Inferno as VM’s “backend” then go ahead =)