is anyone jumping on the riot bandwagon? Aside from that blog post I haven't seen anything about it. I get that JS is changing quickly but in my mind things are settling down as tools get more mature.
That React example is broken (the event handlers aren't binding to this and it's putting <li> inside <li>) and it's not doing the same thing as the Riot version - here's a working version which is a better functionality match:
import React from 'react'
import {render} from 'react-dom'
import Todo from './Todo'
render(<Todo/>, document.querySelector('#app')
From what I've played with of it Riot is a good pick for projects which don't need the power and flexibility which comes with building your UI in code - there's always Mithril.js if you want that functionality in a lighter package. Vue.js is also worth a look if you like Riot's style, as its build tools let you define each component in one file in a similar manner.
The great thing about component-based stuff taking off is that as long as the data flow is mostly top-down, it's not that onerous to try a chunk of your app out in another library/framework.
For those following along at home, this also switches the React from ES2015 style to the original style of building components.
That's because React.createClass automatically binds the this for its callbacks, which is helpful since that's what you usually want, but also somewhat magical. I personally prefer the ES2015 way where you have to be more explicit:
class Todo extends React.Component {
// ...
render () {
<form onSubmit={this.handleSubmit.bind(this)}>
}
This way explicitly binds the handleSubmit function to use the component's this, so the function can do something like this.setState(). Alternatively, you can use ES2015's arrow function which bind's this for you:
class Todo extends React.Component {
// ...
render () {
<form onSubmit={() => this.handleSubmit}>
}
Kind of weird at first, but you get used to it and then it feels more "javascripty".
I switched it as I don't currently see any benefit from using the ES6 class syntax, you end up either having to do more work in a constructor, or recreating event handlers on each render.
I was starting to do this sort of thing when initially porting some components over:
class Todo extends Component {
constructor(props) {
super(props)
this.handleSubmit = this.handleSubmit.bind(this)
}
// ...
}
It's a smell to me that people are enabling experimental features in Babel solely to make the syntax of equivalent components tolerable with React.Component, particularly for statics and methods bound to the instance.
Do you think long term react is moving towards ES6, though? I'm new to react, and was under the impression that that was the direction the project was headed, so have been getting used to the new syntax. Have they made statements either way about long term support of both syntaxes?
I wouldn't expect it to be the next big thing. If you look at things that got big in the past few years (first jQuery, then Angular, now React), they all brought a fairly radical new way of programming to the table. Riot only has, AFAICT, things with the level of impact of a different syntax.
The only thing presently available that I've heard of and see as having a small chance of becoming a game changer is Cycle.js, but then again, that might still be too similar to React.
Really. I'd be interested to hear how React handled input sanitization, xss security, routing, service decorators, inversion of control/dependency injection, abstraction of browser globals to enable better unit testing, and maybe about 100 other things we're using in our Angular 1 app, because I haven't seen any of that stuff in the React docs.
As another comment says you don't need most of this shit in React. React doesn't need an headless browser in order to run tests for instance, unlike AngularJS 1.
22
u/griffonrl Dec 15 '15
Too late.