react.nim
react.nim copied to clipboard
React.createClass removed/deprecated
Starting with React 15.5 the React.createClass has been deprecated and moved into its own module.
Do you think it would be possible to generate the component code exactly the same way the babel transpiler would transform from ES6 class component to the ES5 target?
I'm no expert on this, but inferno also advises against ES5 class component like React.createClass for performance reasons:
Inferno offers ES5 class components as a separate package called inferno-create-class. Note: The recommended way to create Components is Functional components, or by extending ES2015 class Components. This package provides auto bind mechanism same way as old React.createClass({}) but it affects negatively performance.
I'm wondering how this translates to code produced by Nim.
I am not sure what the downside on performance is. I expect functions like React.createClass to do what I would do manually (or with a transpiler): create a constructor function, adjust its prototype property and so on.
In other words, I think that if we generate the component code exactly the same way the babel transpiler would transform from ES6 class component to the ES5 target, we end up with the same thing that React.createClass does (I would have to check to be sure). I guess the slowdown is only for ES6 compatible targets, where maybe the runtime optimizes classes better than prototype based inheritance. Unfortunately, generating ES6 classes is not doable in Nim (I think?).
In any case, this was just a small experiment to see whether it was feasible to use Nim in the browser for a realistic application. If you come up with a better way to handle React classes, I will gladly merge a PR, but otherwise don't hold your breath :-)
:+1: I may look into it.