It’s just data

React.rb

Having determined that Angular.js is overkill for my blog rewrite, I started looking more closely at React.  It occurred to me that I could do better than JSX, so I wrote a Ruby2JS filter.  Compare for yourself.  Excerpt from the React tutorial:

var CommentList = React.createClass({
  render: function() {
    var commentNodes = this.props.data.map(function (comment) {
      return (
        <Comment author={comment.author}>
          {comment.text}
        </Comment>
      );
    });
    return (
      <div className="commentList">
        {commentNodes}
      </div>
    );
  }
});

Equivalent using the Ruby2JS filter:

class CommentList < React 
  def render
    _div.commentList do
      @@data.forEach do |comment|
        _CommentBlock comment.text, author: comment.author
      end
    end
  end
end

Note: I renamed the Comment class to CommentBlock to avoid a conflict with the existing Comment API.  I wouldn’t have thought that would be necessary, but things didn’t work until I made this change.

Full source for the tutorial reimplemented in Ruby is available.


Problem with Comment has been fixed.  Underlying cause was ruby2js attempting to us an ES6 feature: const.

Posted by Sam Ruby at

HyperReact is a wrapper for the React.js library for making UIs. HyperReact gives all the integrity of React joined with the expressiveness of the Ruby dialect.

Posted by assignment help online at

Thanks for the best blog.it was very useful for me. keep sharing such ideas in the future as well. this was actually what i was looking for,and i am glad to came here!

Posted by Godaddy promo code at

Gratitude for the good blog. It was extremely helpful for me. Remain giving out such thoughts in the prospect as fine. This was really what I was appearing for, and I am joyful to arrive here!

Posted by Research Paper Writing Service Cheap at

Add your comment