|
| 1 | +# React::Rails::BenchmarkRenderer |
| 2 | + |
| 3 | +This idea started with a PR I sent to actual react-rails before it hit 1.0 release. I didn't have time to finish it then, |
| 4 | +and the structure of the react-rails codebase changed considerably, so it is now quite easy to write a renderer as a plugin. |
| 5 | + |
| 6 | +This gem is a plugin to ract-rails providing two things: |
| 7 | + |
| 8 | +1. `React::ServerRendering::Concern::Instrumentation` |
| 9 | + - benchmarking instrumentation of the sort found in rails view rendering |
| 10 | + - can be included into any Renderer to add Benchmarking to it |
| 11 | +2. `React::ServerRendering::BenchmarkRenderer` |
| 12 | + - a reference implementation of `React::ServerRendering::Concern::Instrumentation` |
| 13 | + |
| 14 | +## Installation |
| 15 | + |
| 16 | +Add this line to your application's Gemfile: |
| 17 | + |
| 18 | +```ruby |
| 19 | +gem 'react-rails-benchmark_renderer' |
| 20 | +``` |
| 21 | + |
| 22 | +And then execute: |
| 23 | + |
| 24 | + $ bundle |
| 25 | + |
| 26 | +Or install it yourself as: |
| 27 | + |
| 28 | + $ gem install react-rails-benchmark_renderer |
| 29 | + |
| 30 | +## Usage |
| 31 | + |
| 32 | +To simply use the reference implementation, just edit your application.rb with: |
| 33 | + |
| 34 | +``` |
| 35 | + config.react.server_renderer = React::ServerRendering::BenchmarkRenderer |
| 36 | +``` |
| 37 | + |
| 38 | +To roll your own renderer: |
| 39 | + |
| 40 | +Use `Concern::Implementation` to enhance any React ServerRendering Renderer with benchmarking. |
| 41 | + |
| 42 | +Usage is just like you can see in the reference implementation: |
| 43 | + |
| 44 | +```ruby |
| 45 | +require "react/server_rendering/concerns/instrumentation" |
| 46 | +# Extends SprocketsRenderer for benchmarking in the Rails environment |
| 47 | +# - benchmarks rendering in the same manner as Rails view rendering is benchmarked by Rails |
| 48 | +module React |
| 49 | + module ServerRendering |
| 50 | + class BenchmarkRenderer < SprocketsRenderer |
| 51 | + include Concerns::Instrumentation |
| 52 | + end |
| 53 | + end |
| 54 | +end |
| 55 | +``` |
| 56 | + |
| 57 | +## Development |
| 58 | + |
| 59 | +After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment. |
| 60 | + |
| 61 | +To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). |
| 62 | + |
| 63 | +## Contributing |
| 64 | + |
| 65 | +1. Fork it ( https://github.com/[my-github-username]/react-rails-benchmark_renderer/fork ) |
| 66 | +2. Create your feature branch (`git checkout -b my-new-feature`) |
| 67 | +3. Commit your changes (`git commit -am 'Add some feature'`) |
| 68 | +4. Push to the branch (`git push origin my-new-feature`) |
| 69 | +5. Create a new Pull Request |
0 commit comments