question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support JSX for JS (Babel)

See original GitHub issue

In traditional tabris development cycle, we may create many component from scratch. We may need a better method to improve these job. From react and nativescript, they used JSX to slove the proble, but tabris not. I hope tabris js can support smarter solution (eg. JSX options) in future.

Currently, I have found a alternative solution(but not smart) for using JSX in tabrisjs.

First, install babel js transcripter https://babeljs.io/docs/setup/

npm install --save-dev babel-cli babel-preset-es2015

Second, install jsx transcripter plugin(i’m not sure use both or transform-h-jsx only) https://babeljs.io/docs/plugins/syntax-jsx/ , https://www.npmjs.com/package/babel-plugin-transform-h-jsx

npm install --save-dev babel-plugin-syntax-jsx babel-plugin-transform-h-jsx

Third, setup .babelrc like following(may be different):

{ 
	"presets": ["es2015"],
	"plugins": ["transform-es2015-modules-commonjs",
		"transform-h-jsx",
		"syntax-jsx"]
}

Then, we need to add a module to export a method called “h”:

import tabris from "tabris";
export default function h(obj,param, child = []) {
    let o = new obj(param)
    if(child.length > 0) o.append(child);
    return o;
}

After all , in your main development, before you using JSX, you may include the module which includes the h method, and the following sample program will help you to study this alternative method. In this case, the module h is stored in the lib folder.

import 'tabris';
import h from "./lib/h";
let items = [
	{id:0, name:"a"},
	{id:1, name:"b"},
	{id:2, name:"c"},
]
let a = 
	<tabris.Composite id="scroll" left="0" top="0" >
		<tabris.TextView id="lblA" left="10" top="10" text="Title A" />
		<tabris.TextView id="lblB" left="10" top="prev()" text="Title B"/>
		<tabris.TextView id="lblC" left="10" top="prev()" text="Title C" />
		<tabris.Picker id="picker" left="10" top="prev()" items={items} itemText={(i)=>i.name} />
	</tabris.Composite>;
a.appendTo(tabris.ui.contentView);

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

0reactions
tbuschtocommented, Jun 30, 2017

We have documented now how to use it with JavaScript vis the TypeScript compiler. I would consider this fixed, since the result is the same. If there is a definite need to use Babel, please re-open.

Read more comments on GitHub >

github_iconTop Results From Across the Web

babel/preset-react
Though the JSX spec allows this, it is disabled by default since React's JSX does not currently have support for it. pure. boolean...
Read more >
Babel, JSX, and Build Steps - React
Babel, JSX, and Build Steps · Do I need to use JSX with React? · Do I need to use ES6 (+) with...
Read more >
The Role of Babel in React - Medium
Behind the scenes, Babel is a workhorse that ensures we can write concise and expressive React components using JSX. It also takes care...
Read more >
Transform JSX to JS using babel - Stack Overflow
jsx file to main.js. I installed the following babel plugin. npm install --save-dev babel-plugin-transform-react-jsx. Created ...
Read more >
ReactJS | Understanding Babel and JSX - Dev Genius
JSX produces React elements and can embed any JavaScript expression. Ultimately, the JSX is converted to JavaScript using compiler/transformers. Setting up ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found