spine / spine

Lightweight MVC library for building JavaScript applications

Home Page:http://spine.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature request - Use React for View rendering

fabdrol opened this issue · comments

Feature request: replace the current view system with Facebook's React. What do you guys think?

Spine doesn't have a view system per se. Is React more of a controller implementation? I guess I am not sure what would you see changing?

I guess you could see React as a view controller; it manages UI components, their events etc..
Thing is, React is extremely fast, hence the question. I know React has been used with Backbone (by Instagram, amongst others), but unfortunately I don't have enough (intimate) knowledge of Spine's inner workings to implement it transparently (not breaking the normal spine controller API) :-(

This guy wrote about integrating with Backbone, but it doesn't really look "Backbone native"
http://www.thomasboyt.com/2013/12/17/using-reactjs-as-a-backbone-view.html

I've been meaning to play with React... Just haven't found the time yet :(

From the linked article, it doesn't look like it would be very complicated to use React as a view with Spine controllers. You could define a render() method in your controller that did something like this:

render: ->
  widget = new MyWidget
    handleClick: @clickHandler
  React.renderComponent widget, @el.get(0)

clickHandler: =>
  # do stuff...

Then just use @render() instead of Spine's @replace(). I'm not even sure you would need to create a new instance of MyWidget every time...

Can't wait to play with React!

I think you'd probably be better off using Spine.Model in React than trying to go this direction. Not having used React, I'm not sure what the benefit is over using Spine.Controller which already has the events object for handling events. If anything I think this is probably better suited for a plugin, something like Spine.React.