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

Commit bf98dd7

Browse files
committed
Merge branch '1_0_0' into edge
2 parents 3fb640c + 14354e4 commit bf98dd7

File tree

8 files changed

+48
-21
lines changed

8 files changed

+48
-21
lines changed

Appraisals

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ appraise "opal-master-react-15" do
2626
ruby '>= 2.0.0'
2727
gem 'opal', git: 'https://github.com/opal/opal.git'
2828
gem "opal-sprockets", git: 'https://github.com/opal/opal-sprockets.git'
29-
gem 'opal-rails', '~> 0.9.0'
29+
gem 'opal-rails', '~> 0.9.4'
3030
gem 'react-rails', '~> 2.4.0', require: false
3131
end

Gemfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
source 'https://rubygems.org'
22
gem "opal-jquery", git: "https://github.com/opal/opal-jquery.git", branch: "master"
3-
gem "opal-rails", git: "https://github.com/opal/opal-rails.git", branch: "master"
43
gemspec

gemfiles/opal_0_11_react-rails_2_4.gemfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@ source "https://rubygems.org"
22
source ENV['HYPER_DEV_GEM_SOURCE'] if ENV['HYPER_DEV_GEM_SOURCE']
33

44
gem "opal-jquery", git: "https://github.com/opal/opal-jquery.git", branch: "master"
5-
gem "opal-rails", git: "https://github.com/opal/opal-rails.git", branch: "master"
65

76
gemspec :path => "../"

hyper-react.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Gem::Specification.new do |spec|
3333
spec.add_development_dependency 'mime-types'
3434
spec.add_development_dependency 'nokogiri'
3535
spec.add_development_dependency 'opal-jquery'
36-
spec.add_development_dependency 'opal-rails', '~> 0.9.3'
36+
spec.add_development_dependency 'opal-rails', '~> 0.9.4'
3737
spec.add_development_dependency 'opal-rspec'
3838
spec.add_development_dependency 'rails', '>= 4.0.0'
3939
spec.add_development_dependency 'rails-controller-testing'

lib/react/api.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,9 @@ def self.convert_props(properties)
174174
elsif key == 'ref' && value.is_a?(Proc)
175175
props[key] = %x{
176176
function(dom_node){
177-
if (dom_node.__opalInstance !== undefined && dom_node.__opalInstance !== null) {
177+
if (dom_node !== null && dom_node.__opalInstance !== undefined && dom_node.__opalInstance !== null) {
178178
#{ value.call(`dom_node.__opalInstance`) };
179-
} else if(ReactDOM.findDOMNode !== undefined && dom_node.nodeType === undefined) {
179+
} else if(dom_node !== null && ReactDOM.findDOMNode !== undefined && dom_node.nodeType === undefined) {
180180
#{ value.call(`ReactDOM.findDOMNode(dom_node)`) };
181181
} else {
182182
#{ value.call(`dom_node`) };

lib/react/event.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,27 @@ class Event
3131
# Focus
3232
alias_native :related_target, :relatedTarget
3333
# Mouse
34-
alias_native :alt_key, :altKey
34+
# aliased above: alias_native :alt_key, :altKey
3535
alias_native :button, :button
3636
alias_native :buttons, :buttons
3737
alias_native :client_x, :clientX
3838
alias_native :client_y, :clientY
39-
alias_native :ctrl_key, :ctrlKey
39+
# aliased above: alias_native :ctrl_key, :ctrlKey
4040
alias_native :get_modifier_state, :getModifierState
41-
alias_native :meta_key, :metaKey
41+
# aliased above: alias_native :meta_key, :metaKey
4242
alias_native :page_x, :pageX
4343
alias_native :page_y, :pageY
44-
alias_native :related_target, :relatedTarget
44+
# aliased above: alias_native :related_target, :relatedTarget
4545
alias_native :screen_x, :screen_x
4646
alias_native :screen_y, :screen_y
47-
alias_native :shift_key, :shift_key
47+
# aliased above: alias_native :shift_key, :shift_key
4848
# Touch
49-
alias_native :alt_key, :altKey
49+
# aliased above: alias_native :alt_key, :altKey
5050
alias_native :changed_touches, :changedTouches
51-
alias_native :ctrl_key, :ctrlKey
52-
alias_native :get_modifier_state, :getModifierState
53-
alias_native :meta_key, :metaKey
54-
alias_native :shift_key, :shiftKey
51+
# aliased above: alias_native :ctrl_key, :ctrlKey
52+
# aliased above: alias_native :get_modifier_state, :getModifierState
53+
# aliased above: alias_native :meta_key, :metaKey
54+
# aliased above: alias_native :shift_key, :shiftKey
5555
alias_native :target_touches, :targetTouches
5656
alias_native :touches, :touches
5757
# UI
@@ -64,10 +64,10 @@ class Event
6464
alias_native :delta_z, :deltaZ
6565

6666
BUILT_IN_EVENTS = %w{onCopy onCut onPaste onKeyDown onKeyPress onKeyUp
67-
onFocus onBlur onChange onInput onSubmit onClick onDoubleClick onDrag
67+
onFocus onBlur onChange onInput onSubmit onClick onContextMenu onDoubleClick onDrag
6868
onDragEnd onDragEnter onDragExit onDragLeave onDragOver onDragStart onDrop
6969
onMouseDown onMouseEnter onMouseLeave onMouseMove onMouseOut onMouseOver
70-
onMouseUp onTouchCancel onTouchEnd onTouchMove onTouchStart onScroll}
70+
onMouseUp onSelect onTouchCancel onTouchEnd onTouchMove onTouchStart onScroll onWheel}
7171

7272
def initialize(native_element)
7373
@native = native_element

lib/react/ref_callback.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ def self.convert_props(properties)
1414
props.map do |key, value|
1515
if key == "ref" && value.is_a?(Proc)
1616
new_proc = Proc.new do |native_inst|
17-
if `#{native_inst}.__opalInstance !== undefined && #{native_inst}.__opalInstance !== null`
17+
if `#{native_inst} !== null && #{native_inst}.__opalInstance !== undefined && #{native_inst}.__opalInstance !== null`
1818
value.call(`#{native_inst}.__opalInstance`)
19-
elsif `ReactDOM.findDOMNode !== undefined && #{native_inst}.nodeType === undefined`
19+
elsif `#{native_inst} !== null && ReactDOM.findDOMNode !== undefined && #{native_inst}.nodeType === undefined`
2020
value.call(`ReactDOM.findDOMNode(#{native_inst})`) # react >= v0.15.`)
2121
else
2222
value.call(native_inst)

spec/react/refs_callback_spec.rb

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,36 @@ def render
5959

6060
element = React.create_element(Foo)
6161
React::Test::Utils.render_into_document(element)
62-
"#{Foo.bar.JS['nodeType']}" # aboids json serialisation errors by using "#{}"
62+
"#{Foo.bar.JS['nodeType']}" # avoids json serialisation errors by using "#{}"
6363
end.to eq("1")
6464
end
65+
66+
it "works, even when the component is unmounted" do
67+
# was a bug, on unmount react calls the ref method with null instead of a dom node
68+
# callback failed then
69+
# ref is called two times, once on mount with dom_node, once on unmount with null
70+
mount "Foo" do
71+
class Unmountable < Hyperloop::Component
72+
render do
73+
DIV { "This is a Component" }
74+
end
75+
end
76+
Foo.class_eval do
77+
def ref_rec(dom_node)
78+
@@rec_cnt ||= 0
79+
@@rec_cnt += 1
80+
end
81+
def self.rec_cnt
82+
@@rec_cnt
83+
end
84+
85+
after_mount { mutate.unmount true }
86+
87+
render do
88+
Unmountable(ref: method(:ref_rec).to_proc) unless state.unmount
89+
end
90+
end
91+
end
92+
expect_evaluate_ruby('Foo.rec_cnt').to eq(2)
93+
end
6594
end

0 commit comments

Comments
 (0)