infernojs / babel-plugin-inferno

Transforms JSX to InfernoJS vNodes
MIT License
79 stars 26 forks source link

pragma support #18

Closed mstijak closed 8 years ago

mstijak commented 8 years ago

I find this helpful for switching between React or Inferno during development.

trueadm commented 8 years ago

@mstijak does this even work with React?

mstijak commented 8 years ago

@trueadm Let me explain how this works. In my app I have a large number of components. Each component uses JSX in the render method and that gets translated into React.createElement or Inferno.createBlueprint calls. Switching from React to Inferno requires changing import statements on top of each component file, which is a real pain. React already supports pragma option which allows you to replace React.createElement calls with something else. In this pull request I added the same for Inferno and now it's possible to set that both target the same name.

["babel-plugin-inferno", { "pragma" : "Lib" }],
or
["babel-plugin-transform-react-jsx", { "pragma": "VDOM.createElement" }],
React.createElement -> Lib.createElement
React.Component -> Lib.Component
Inferno.createBlueprint -> Lib.createBlueprint
Inferno.Component -> Lib.Component

On top of each file

import Lib from './Lib'
//import React from 'react'; //not required anymore
//import Inferno from 'inferno'; //not required anymore

And Lib.js

export React as Lib from 'react';
//or
export Inferno as Lib from 'inferno';
// some details missing here

That's the general picture. Some details are missing.

If there is a better way I would be very glad to hear about it.

trueadm commented 8 years ago

@mstijak makes sense! :) merged

Havunen commented 8 years ago

cool feature :+1: