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

Commit 9422399

Browse files
committed
all specs passing with hyper-store embedded and new deprecations
1 parent ae340ca commit 9422399

26 files changed

+257
-477
lines changed

.rubocop.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ Style/LineEndConcatenation:
716716
line end.
717717
Enabled: false
718718

719-
Style/MethodCallParentheses:
719+
Style/MethodCallWithoutArgsParentheses:
720720
Description: 'Do not use parentheses for method calls with no arguments.'
721721
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-args-no-parens'
722722
Enabled: false

Gemfile

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
source 'https://rubygems.org'
22
gemspec
33

4-
ruby ">= 1.9.3"
4+
gem 'hyper-store', path: '../hyper-store'
5+
6+
ruby ">= 1.9.3"
57

68
group :development do
79
gem "appraisal"

gemfiles/opal_0.10_react_15.gemfile

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ source "https://rubygems.org"
44

55
ruby ">= 1.9.3"
66

7+
gem 'hyper-store', path: '../../hyper-store'
8+
79
gem "opal", "~> 0.10.0"
810
gem "opal-rails", "~> 0.9.0"
911
gem "react-rails", "~> 1.10.0", :require => false

hyper-react.gemspec

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Gem::Specification.new do |s|
2121
s.add_dependency 'opal', '>= 0.8.0'
2222
s.add_dependency 'opal-activesupport', '>= 0.2.0'
2323
s.add_dependency 'react-rails'
24+
s.add_dependency 'hyper-store'
2425
s.add_development_dependency 'rake', '< 11.0'
2526
s.add_development_dependency 'rspec-rails', '3.3.3'
2627
s.add_development_dependency 'timecop'
@@ -33,6 +34,7 @@ Gem::Specification.new do |s|
3334
s.add_development_dependency 'mime-types', '< 3'
3435
s.add_development_dependency 'opal-rails'
3536
s.add_development_dependency 'nokogiri', '< 1.7'
37+
s.add_development_dependency 'rubocop'
3638
if RUBY_PLATFORM == 'java'
3739
s.add_development_dependency 'jdbc-sqlite3'
3840
s.add_development_dependency 'activerecord-jdbcsqlite3-adapter'

lib/hyper-react.rb

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11

22

33
if RUBY_ENGINE == 'opal'
4+
5+
module Hyperloop
6+
class Component
7+
end
8+
end
9+
410
if `Opal.global.React === undefined || Opal.global.React.version === undefined`
511
raise [
612
"No React.js Available",
@@ -32,7 +38,17 @@
3238
require 'reactive-ruby/isomorphic_helpers'
3339
require 'rails-helpers/top_level_rails_component'
3440
require 'reactive-ruby/version'
35-
41+
module Hyperloop
42+
class Component
43+
def self.inherited(child)
44+
child.include(Mixin)
45+
end
46+
end
47+
end
48+
React::Component.deprecation_warning(
49+
'components.rb',
50+
"Requiring 'hyper-react' is deprecated. Use gem 'hyper-component', and require 'hyper-component' instead."
51+
) unless defined? Hyperloop::Component::VERSION
3652
else
3753
require 'opal'
3854
# rubocop:disable Lint/HandleExceptions

lib/rails-helpers/top_level_rails_component.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module React
22
class TopLevelRailsComponent
3-
include React::Component
3+
include Hyperloop::Component::Mixin
44

55
def self.search_path
66
@search_path ||= [Module]

lib/react/component.rb

+135-106
Original file line numberDiff line numberDiff line change
@@ -3,137 +3,166 @@
33
require 'active_support/core_ext/class/attribute'
44
require 'react/callbacks'
55
require 'react/rendering_context'
6-
require 'react/observable'
7-
require 'react/state'
6+
require 'hyper-store'
7+
require 'react/state_wrapper'
88
require 'react/component/api'
99
require 'react/component/class_methods'
1010
require 'react/component/props_wrapper'
1111
require 'native'
1212

13-
module React
14-
module Component
15-
def self.included(base)
16-
base.include(API)
17-
base.include(Callbacks)
18-
base.include(Tags)
19-
base.include(DslInstanceMethods)
20-
base.include(ShouldComponentUpdate)
21-
base.class_eval do
22-
class_attribute :initial_state
23-
define_callback :before_mount
24-
define_callback :after_mount
25-
define_callback :before_receive_props
26-
define_callback :before_update
27-
define_callback :after_update
28-
define_callback :before_unmount
29-
end
30-
base.extend(ClassMethods)
31-
end
13+
module Hyperloop
14+
class Component
15+
module Mixin
16+
def self.included(base)
17+
base.include(Store::Mixin)
18+
base.include(React::Component::API)
19+
base.include(React::Component::Callbacks)
20+
base.include(React::Component::Tags)
21+
base.include(React::Component::DslInstanceMethods)
22+
base.include(React::Component::ShouldComponentUpdate)
23+
base.class_eval do
24+
class_attribute :initial_state
25+
define_callback :before_mount
26+
define_callback :after_mount
27+
define_callback :before_receive_props
28+
define_callback :before_update
29+
define_callback :after_update
30+
define_callback :before_unmount
31+
end
32+
base.extend(React::Component::ClassMethods)
33+
end
3234

33-
def self.deprecation_warning(message)
34-
@deprecation_messages ||= []
35-
message = "Warning: Deprecated feature used in #{name}. #{message}"
36-
unless @deprecation_messages.include? message
37-
@deprecation_messages << message
38-
IsomorphicHelpers.log message, :warning
35+
def self.deprecation_warning(message)
36+
React::Component.deprecation_warning(name, message)
3937
end
40-
end
4138

42-
def initialize(native_element)
43-
@native = native_element
44-
end
39+
def deprecation_warning(message)
40+
React::Component.deprecation_warning(self.class.name, message)
41+
end
4542

46-
def emit(event_name, *args)
47-
params["_on#{event_name.to_s.event_camelize}"].call(*args)
48-
end
43+
def initialize(native_element)
44+
@native = native_element
45+
init_store
46+
end
4947

50-
def component_will_mount
51-
IsomorphicHelpers.load_context(true) if IsomorphicHelpers.on_opal_client?
52-
set_state! initial_state if initial_state
53-
State.initialize_states(self, initial_state)
54-
State.set_state_context_to(self) { run_callback(:before_mount) }
55-
rescue Exception => e
56-
self.class.process_exception(e, self)
57-
end
48+
def emit(event_name, *args)
49+
params["_on#{event_name.to_s.event_camelize}"].call(*args)
50+
end
5851

59-
def component_did_mount
60-
State.set_state_context_to(self) do
61-
run_callback(:after_mount)
62-
State.update_states_to_observe
52+
def component_will_mount
53+
React::IsomorphicHelpers.load_context(true) if React::IsomorphicHelpers.on_opal_client?
54+
# set_state! initial_state if initial_state
55+
# State.initialize_states(self, initial_state)
56+
React::State.set_state_context_to(self) { run_callback(:before_mount) }
57+
rescue Exception => e
58+
self.class.process_exception(e, self)
6359
end
64-
rescue Exception => e
65-
self.class.process_exception(e, self)
66-
end
6760

68-
def component_will_receive_props(next_props)
69-
# need to rethink how this works in opal-react, or if its actually that useful within the react.rb environment
70-
# for now we are just using it to clear processed_params
71-
State.set_state_context_to(self) { self.run_callback(:before_receive_props, Hash.new(next_props)) }
72-
rescue Exception => e
73-
self.class.process_exception(e, self)
74-
end
61+
def component_did_mount
62+
React::State.set_state_context_to(self) do
63+
run_callback(:after_mount)
64+
React::State.update_states_to_observe
65+
end
66+
rescue Exception => e
67+
self.class.process_exception(e, self)
68+
end
7569

76-
def component_will_update(next_props, next_state)
77-
State.set_state_context_to(self) { self.run_callback(:before_update, Hash.new(next_props), Hash.new(next_state)) }
78-
rescue Exception => e
79-
self.class.process_exception(e, self)
80-
end
70+
def component_will_receive_props(next_props)
71+
# need to rethink how this works in opal-react, or if its actually that useful within the react.rb environment
72+
# for now we are just using it to clear processed_params
73+
React::State.set_state_context_to(self) { self.run_callback(:before_receive_props, Hash.new(next_props)) }
74+
rescue Exception => e
75+
self.class.process_exception(e, self)
76+
end
8177

82-
def component_did_update(prev_props, prev_state)
83-
State.set_state_context_to(self) do
84-
self.run_callback(:after_update, Hash.new(prev_props), Hash.new(prev_state))
85-
State.update_states_to_observe
78+
def component_will_update(next_props, next_state)
79+
React::State.set_state_context_to(self) { self.run_callback(:before_update, Hash.new(next_props), Hash.new(next_state)) }
80+
rescue Exception => e
81+
self.class.process_exception(e, self)
8682
end
87-
rescue Exception => e
88-
self.class.process_exception(e, self)
89-
end
9083

91-
def component_will_unmount
92-
State.set_state_context_to(self) do
93-
self.run_callback(:before_unmount)
94-
State.remove
84+
def component_did_update(prev_props, prev_state)
85+
React::State.set_state_context_to(self) do
86+
self.run_callback(:after_update, Hash.new(prev_props), Hash.new(prev_state))
87+
React::State.update_states_to_observe
88+
end
89+
rescue Exception => e
90+
self.class.process_exception(e, self)
9591
end
96-
rescue Exception => e
97-
self.class.process_exception(e, self)
98-
end
9992

100-
attr_reader :waiting_on_resources
93+
def component_will_unmount
94+
React::State.set_state_context_to(self) do
95+
self.run_callback(:before_unmount)
96+
React::State.remove
97+
end
98+
rescue Exception => e
99+
self.class.process_exception(e, self)
100+
end
101101

102-
def update_react_js_state(object, name, value)
103-
if object
104-
name = "#{object.class}.#{name}" unless object == self
105-
set_state(
106-
'***_state_updated_at-***' => Time.now.to_f,
107-
name => value
108-
)
109-
else
110-
set_state name => value
102+
attr_reader :waiting_on_resources
103+
104+
def update_react_js_state(object, name, value)
105+
if object
106+
name = "#{object.class}.#{name}" unless object == self
107+
set_state(
108+
'***_state_updated_at-***' => Time.now.to_f,
109+
name => value
110+
)
111+
else
112+
set_state name => value
113+
end
111114
end
112-
end
113115

114-
def render
115-
raise 'no render defined'
116-
end unless method_defined?(:render)
117-
118-
def _render_wrapper
119-
State.set_state_context_to(self, true) do
120-
element = React::RenderingContext.render(nil) { render || '' }
121-
@waiting_on_resources =
122-
element.waiting_on_resources if element.respond_to? :waiting_on_resources
123-
element
124-
end
125-
# rubocop:disable Lint/RescueException # we want to catch all exceptions regardless
126-
rescue Exception => e
127-
# rubocop:enable Lint/RescueException
128-
self.class.process_exception(e, self)
129-
end
116+
def render
117+
raise 'no render defined'
118+
end unless method_defined?(:render)
119+
120+
def _render_wrapper
121+
React::State.set_state_context_to(self, true) do
122+
element = React::RenderingContext.render(nil) { render || '' }
123+
@waiting_on_resources =
124+
element.waiting_on_resources if element.respond_to? :waiting_on_resources
125+
element
126+
end
127+
# rubocop:disable Lint/RescueException # we want to catch all exceptions regardless
128+
rescue Exception => e
129+
# rubocop:enable Lint/RescueException
130+
self.class.process_exception(e, self)
131+
end
130132

131-
def watch(value, &on_change)
132-
Observable.new(value, on_change)
133+
def watch(value, &on_change)
134+
Observable.new(value, on_change)
135+
end
136+
137+
def define_state(*args, &block)
138+
React::State.initialize_states(self, self.class.define_state(*args, &block))
139+
end
133140
end
141+
end
142+
end
134143

135-
def define_state(*args, &block)
136-
State.initialize_states(self, self.class.define_state(*args, &block))
144+
module React
145+
module Component
146+
def self.included(base)
147+
# note this is turned off during old style testing: See the spec_helper
148+
deprecation_warning base, "The module name React::Component has been deprecated. Use Hyperloop::Component::Mixin instead."
149+
base.include Hyperloop::Component::Mixin
150+
end
151+
def self.deprecation_warning(name, message)
152+
@deprecation_messages ||= []
153+
message = "Warning: Deprecated feature used in #{name}. #{message}"
154+
unless @deprecation_messages.include? message
155+
@deprecation_messages << message
156+
React::IsomorphicHelpers.log message, :warning
157+
end
137158
end
138159
end
160+
module ComponentNoNotice
161+
def self.included(base)
162+
base.include Hyperloop::Component::Mixin
163+
end
164+
end
165+
end
166+
167+
module React
139168
end

lib/react/component/base.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ module React
22
module Component
33
class Base
44
def self.inherited(child)
5-
child.include(Component)
5+
# note this is turned off during old style testing: See the spec_helper
6+
unless child.to_s == "React::Component::HyperTestDummy"
7+
React::Component.deprecation_warning child, "The class name React::Component::Base has been deprecated. Use Hyperloop::Component instead."
8+
end
9+
child.include(ComponentNoNotice)
610
end
711
end
812
end

0 commit comments

Comments
 (0)