Skip to content
This repository was archived by the owner on Oct 19, 2018. It is now read-only.

Commit e0f7b19

Browse files
authored
Merge pull request #171 from reactrb/feature/react-source
New way to load reactjs sources
2 parents 42453bc + bce6f00 commit e0f7b19

File tree

14 files changed

+52
-46
lines changed

14 files changed

+52
-46
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ Whitespace conventions:
2020

2121
## [0.9.0] - Unreleased
2222

23+
### Added
24+
25+
- `react/react-source` is the suggested way to include ReactJS sources now. Simply require `react/react-source` immediately before the `require "reactrb"` in your Opal code will make it work.
26+
27+
### Deprecated
28+
29+
- `react-latest` & `react-v1x` is deprecated. Use `react/react-source` instead.
30+
2331
### Removed
2432

2533
- `opal-browser` is removed from runtime dependency. (#133)

README.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Reactrb / Reactive-Ruby
1+
# Reactrb / Reactive-Ruby
22

33
[![Join the chat at https://gitter.im/reactrb/chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/reactrb/chat?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
44
[![Build Status](https://travis-ci.org/reactrb/reactrb.svg?branch=master)](https://travis-ci.org/reactrb/reactrb)
@@ -72,13 +72,10 @@ It is very unlikely that there will be any more releases of the `reactive-ruby`
7272
There are no syntactic or semantic breaking changes between `reactrb` v 0.8.x and
7373
previous versions, however the `reactrb` gem does *not* include the react-js source as previous versions did. This allows you to pick the react js source compatible with other gems and react js components you may be using.
7474

75-
To upgrade, replace `reactive-ruby` with `reactrb`, both in your Gemfile, and in any `requires` in your code. You will also need to require react-js as this is no longer included in the gem.
75+
Follow these steps to upgrade:
7676

77-
If you are using react-rails then simply find anyplace where you `require 'reactrb'` and immediately before this do a `require 'react'` which will load the compatible react js file.
78-
79-
If you are using webpack then add `react` to your manifest.
80-
81-
If you are not using react-rails then find where you `require 'reactrb'` and immediately before this do a `require 'react-latest'` (or 'react-v13', 'react-v14' or 'react-v15')
77+
1. Replace `reactive-ruby` with `reactrb` both in **Gemfile** and any `require`s in your code.
78+
2. To include the React.js source, the suggested way is to add `require 'react/react-source'` before `require 'reactrb'`. This will use the copy of React.js source from `react-rails` gem.
8279

8380
# Roadmap
8481

Rakefile

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,9 @@ ENV['REAL_BUNDLE_GEMFILE'] = ENV['BUNDLE_GEMFILE']
99
require 'rspec/core/rake_task'
1010
require 'opal/rspec/rake_task'
1111

12-
begin
13-
require "react-rails"
14-
rescue NameError
15-
end
16-
1712
RSpec::Core::RakeTask.new('ruby:rspec')
1813

1914
Opal::RSpec::RakeTask.new('opal:rspec') do |s, task|
20-
s.append_path React::Rails::AssetVariant.new(addons: true).react_directory
2115
s.append_path 'spec/vendor'
2216
s.index_path = 'spec/index.html.erb'
2317
task.timeout = 80000 if task

config.ru

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,19 @@ Bundler.require
44
require "opal/rspec"
55
require "opal-jquery"
66

7-
begin
8-
require "react-rails"
9-
rescue NameError
10-
end
11-
127
if Opal::RSpec.const_defined?("SprocketsEnvironment")
138
sprockets_env = Opal::RSpec::SprocketsEnvironment.new
149
sprockets_env.cache = Sprockets::Cache::FileStore.new("tmp")
1510
sprockets_env.add_spec_paths_to_sprockets
1611
run Opal::Server.new(sprockets: sprockets_env) { |s|
1712
s.main = 'opal/rspec/sprockets_runner'
18-
s.append_path React::Rails::AssetVariant.new(addons: true).react_directory
1913
s.debug = false
2014
s.append_path 'spec/vendor'
2115
s.index_path = 'spec/index.html.erb'
2216
}
2317
else
2418
run Opal::Server.new { |s|
2519
s.main = 'opal/rspec/sprockets_runner'
26-
s.append_path React::Rails::AssetVariant.new(addons: true).react_directory
2720
s.append_path 'spec'
2821
s.append_path 'spec/vendor'
2922
s.debug = false
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
// A placeholder file to prevent file not found error of requireing
2-
// `react-server` in spec_helper.rb.
2+
// `react-server` in react/react-source

lib/react/react-source.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
if RUBY_ENGINE == 'opal'
2+
require 'react.js'
3+
require "react-server.js"
4+
else
5+
require "react/rails/asset_variant"
6+
react_directory = React::Rails::AssetVariant.new(addons: true).react_directory
7+
Opal.append_path react_directory.untaint
8+
Opal.append_path File.expand_path('../../react-sources/', __FILE__).untaint
9+
end

lib/reactive-ruby.rb

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,12 @@
55
raise [
66
"No React.js Available",
77
"",
8-
"React.js must be defined before requiring 'reactive-ruby'",
9-
"'reactive-ruby' has been tested with react v13, v14, and v15.",
8+
"A global `React` must be defined before requiring 'reactive-ruby'",
109
"",
11-
"IF USING 'react-rails':",
12-
" add 'require \"react\"' immediately before the 'require \"reactive-ruby\" directive in 'views/components.rb'.",
10+
"To USE THE BUILT-IN SOURCE: ",
11+
" add 'require \"react/react-source\"' immediately before the 'require \"reactive-ruby\" directive.",
1312
"IF USING WEBPACK:",
14-
" add 'react' to your webpack manifest.",
15-
"OTHERWISE TO GET THE LATEST TESTED VERSION",
16-
" add 'require \"react-latest\"' immediately before the require of 'reactive-ruby',",
17-
"OR TO USE A SPECIFIC VERSION",
18-
" add 'require \"react-v1x\"' immediately before the require of 'reactive-ruby'."
13+
" add 'react' to your webpack manifest."
1914
].join("\n")
2015
end
2116
require 'react/top_level'
@@ -49,4 +44,5 @@
4944

5045
Opal.append_path File.expand_path('../', __FILE__).untaint
5146
Opal.append_path File.expand_path('../sources/', __FILE__).untaint
47+
require "react/react-source"
5248
end

lib/reactrb.rb

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@
22

33
if RUBY_ENGINE == 'opal'
44
if `window.React === undefined || window.React.version === undefined`
5-
raise "No React.js Available\n\n"\
6-
"React.js must be defined before requiring 'reactrb'\n"\
7-
"'reactrb' has been tested with react v13, v14, and v15.\n\n"\
8-
"IF USING 'react-rails':\n"\
9-
" add 'require \"react\"' immediately before the 'require \"reactive-ruby\" "\
10-
"directive in 'views/components.rb'.\n"\
11-
"IF USING WEBPACK:\n"\
12-
" add 'react' to your webpack manifest.\n"\
13-
"OTHERWISE TO GET THE LATEST TESTED VERSION\n"\
14-
" add 'require \"react-latest\"' immediately before the require of 'reactrb',\n"\
15-
"OR TO USE A SPECIFIC VERSION\n"\
16-
" add 'require \"react-v1x\"' immediately before the require of 'reactrb'."
5+
raise [
6+
"No React.js Available",
7+
"",
8+
"A global `React` must be defined before requiring 'reactrb'",
9+
"",
10+
"To USE THE BUILT-IN SOURCE: ",
11+
" add 'require \"react/react-source\"' immediately before the 'require \"reactrb\" directive.",
12+
"IF USING WEBPACK:",
13+
" add 'react' to your webpack manifest."
14+
].join("\n")
1715
end
1816
require 'react/hash'
1917
require 'react/top_level'
@@ -50,4 +48,5 @@
5048

5149
Opal.append_path File.expand_path('../', __FILE__).untaint
5250
Opal.append_path File.expand_path('../sources/', __FILE__).untaint
51+
require "react/react-source"
5352
end

lib/sources/react-latest.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
console.error("Warning: loading `react-latest` directly is deprecated. Replace the requires with `react/react-source`.");
2+
13
/**
24
* React (with addons) v15.0.1
35
*/

lib/sources/react-v13.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
console.error("Warning: loading `react-v13` directly is deprecated. ")
2+
console.error("Replace the requires with `react/react-source` and add `gem 'react-rails', '~> 1.3.3'` to your Gemfile.");
3+
14
/**
25
* React (with addons) v0.13.3
36
*/
@@ -21639,4 +21642,4 @@ if ("production" !== "development") {
2163921642
module.exports = warning;
2164021643

2164121644
},{"129":129}]},{},[1])(1)
21642-
});
21645+
});

0 commit comments

Comments
 (0)