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

Commit 0a12815

Browse files
authored
Merge pull request #203 from ruby-hyperloop/feature/config
Add React::Config
2 parents 8370b95 + 9c76e4a commit 0a12815

File tree

5 files changed

+59
-2
lines changed

5 files changed

+59
-2
lines changed

lib/react/config.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
if RUBY_ENGINE != 'opal'
2+
require "react/config/server"
3+
else
4+
require "react/config/client"
5+
end

lib/react/config/client.rb.erb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
if RUBY_ENGINE == 'opal'
2+
module React
3+
module Config
4+
extend self
5+
def environment=(value)
6+
raise "Environment cannot be configured at runtime."
7+
end
8+
9+
def config
10+
hash = %x{
11+
Opal.hash({
12+
environment: <%= '"' + React::Config.config[:environment] + '"' %>
13+
})
14+
}
15+
hash
16+
end
17+
end
18+
end
19+
end

lib/react/config/server.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
if RUBY_ENGINE != 'opal'
2+
module React
3+
module Config
4+
extend self
5+
def environment=(value)
6+
config[:environment] = value
7+
end
8+
9+
def config
10+
@config ||= default_config
11+
end
12+
13+
def default_config
14+
{
15+
environment: ENV['RACK_ENV'] || 'development'
16+
}
17+
end
18+
end
19+
end
20+
end

lib/react/react-source.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@
44
"Warning: `react/react-source` is deprecated, ",
55
"use `react/react-source-browser` or `react/react-source-server` instead."
66
]
7-
console.error(ms.join(""));
7+
console.error(ms.join(""));
88
}
99
require 'react.js'
1010
require "react-server.js"
1111
else
12+
require "react/config"
1213
require "react/rails/asset_variant"
13-
react_directory = React::Rails::AssetVariant.new(addons: true).react_directory
14+
react_directory = React::Rails::AssetVariant.new(
15+
addons: true,
16+
variant: React::Config.config[:environment].to_sym
17+
).react_directory
1418
Opal.append_path react_directory.untaint
1519
Opal.append_path File.expand_path('../../react-sources/', __FILE__).untaint
1620
end

lib/reactive-ruby/isomorphic_helpers.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require "react/config"
2+
13
module React
24
module IsomorphicHelpers
35
def self.included(base)
@@ -28,6 +30,13 @@ def self.load_context(unique_id = nil, name = nil)
2830

2931
def self.log(message, message_type = :info)
3032
message = [message] unless message.is_a? Array
33+
34+
is_production = React::Config.config[:environment] == 'production'
35+
36+
if (message_type == :info || message_type == :warning) && is_production
37+
return
38+
end
39+
3140
if message_type == :info
3241
if on_opal_server?
3342
style = 'background: #00FFFF; color: red'

0 commit comments

Comments
 (0)