ViewModel + Inferno

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.

6 Likes

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

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

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.

1 Like

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?

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.

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

So how do we use inferno?

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.

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.

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.

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?

1 Like

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

1 Like