3 ms·
I don't think CoffeeScript would benefit much from JSX, since the sugar for function calls and object literals applies well to React. For example, one of the ex
by plorkyeran 13y ago
I don't think CoffeeScript would benefit much from JSX, since the sugar for function calls and object literals applies well to React. For example, one of the examples from the React page translated to plain CoffeeScript:
JSX:
<div>
<h3>TODO</h3>
<TodoList items={this.state.items} />
<form onSubmit={this.handleSubmit}>
<input onChange={this.onChange} value={this.state.text} />
<button>{'Add #' + (this.state.items.length + 1)}</button>
</form>
</div>
CS:
R.div null,
R.h3 null, 'TODO'
TodoList items: @state.items
R.form onSubmit: @handleSubmit,
R.input onChange: @onChange, value: @state.text
R.button null, "Add ##{@state.items.length +1}"
A hypothetical CSX would probably be more along the lines of Haml or Slim than XML syntax (closing tags would be pretty weird and out of place), and plain CS isn't that different from them already.
- rubiquity 13y agoIn CoffeeScript you can use backticks and still use JSX. Example: `/** @jsx React.DOM */` Todo = React.createClass render: -> ` <div> <h3>TODO</h3> <TodoList items={this.state.items} /> <form onSubmit={this.handleSubmit}> <input onChange={this.onChange} value={this.state.text} /> <button>{'Add #' + (this.state.items.length + 1)}</button> </form> </div> ` Just remember when compiling the CoffeeScript files to pass the bare, and --no-header flags. coffee -bc --no-header todo.coffee
- jbeja 13y agoIs worth notice that there is also: https://github.com/atom/react-coffee https://github.com/atom/react-coffee. class Welcome extends Component render: -> @div -> @text "Hello" @span @props.name component = new Welcome(name: "World") element = component.buildElement()</pre>
- skrebbel 13y agoNo, that is not sufficient. The point is getting designers to shift paradigm and start writing React components. This is a major shift, because while the designers I've worked with have all done a little JavaScript here and there, it's seldom much more than copy/pasting some jQuery code from Stack Overflow. HTML/CSS is their home turf. To you, the CoffeeScript literals might be just as good as the JSX stuff, but to someone who's already out of his comfort zone because the markup is in the middle of all kinds of weird React.createClass stuff, it's a very major difference. JSX really strikes a sweet spot here.