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

Commit 1b8a176

Browse files
committed
Hash native state/props before passing to callback
1 parent c97fd4d commit 1b8a176

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

lib/react/api.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,19 @@ def self.create_native_react_class(type)
3131
},
3232
componentWillReceiveProps: function(next_props) {
3333
var instance = this._getOpalInstance.apply(this);
34-
return #{`instance`.component_will_receive_props(`next_props`) if type.method_defined? :component_will_receive_props};
34+
return #{`instance`.component_will_receive_props(Hash.new(`next_props`)) if type.method_defined? :component_will_receive_props};
3535
},
3636
shouldComponentUpdate: function(next_props, next_state) {
3737
var instance = this._getOpalInstance.apply(this);
38-
return #{`instance`.should_component_update?(`next_props`, `next_state`) if type.method_defined? :should_component_update?};
38+
return #{`instance`.should_component_update?(Hash.new(`next_props`), Hash.new(`next_state`)) if type.method_defined? :should_component_update?};
3939
},
4040
componentWillUpdate: function(next_props, next_state) {
4141
var instance = this._getOpalInstance.apply(this);
42-
return #{`instance`.component_will_update(`next_props`, `next_state`) if type.method_defined? :component_will_update};
42+
return #{`instance`.component_will_update(Hash.new(`next_props`), Hash.new(`next_state`)) if type.method_defined? :component_will_update};
4343
},
4444
componentDidUpdate: function(prev_props, prev_state) {
4545
var instance = this._getOpalInstance.apply(this);
46-
return #{`instance`.component_did_update(`prev_props`, `prev_state`) if type.method_defined? :component_did_update};
46+
return #{`instance`.component_did_update(Hash.new(`prev_props`), Hash.new(`prev_state`)) if type.method_defined? :component_did_update};
4747
},
4848
componentWillUnmount: function() {
4949
var instance = this._getOpalInstance.apply(this);

lib/react/component.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def component_will_receive_props(next_props)
116116
# useful within the react.rb environment for now we are just using it to
117117
# clear processed_params
118118
State.set_state_context_to(self) do
119-
self.run_callback(:before_receive_props, Hash.new(next_props))
119+
self.run_callback(:before_receive_props, next_props)
120120
end
121121
rescue Exception => e
122122
self.class.process_exception(e, self)
@@ -129,9 +129,8 @@ def props_changed?(next_props)
129129

130130
def should_component_update?(next_props, next_state)
131131
State.set_state_context_to(self) do
132-
next_props = Hash.new(next_props)
133132
if self.respond_to?(:needs_update?)
134-
!!self.needs_update?(next_props, Hash.new(next_state))
133+
!!self.needs_update?(next_props, next_state)
135134
elsif false # switch to true to force updates per standard react
136135
true
137136
elsif props_changed? next_props
@@ -150,15 +149,15 @@ def should_component_update?(next_props, next_state)
150149

151150
def component_will_update(next_props, next_state)
152151
State.set_state_context_to(self) do
153-
self.run_callback(:before_update, Hash.new(next_props), Hash.new(next_state))
152+
self.run_callback(:before_update, next_props, next_state)
154153
end
155154
rescue Exception => e
156155
self.class.process_exception(e, self)
157156
end
158157

159158
def component_did_update(prev_props, prev_state)
160159
State.set_state_context_to(self) do
161-
self.run_callback(:after_update, Hash.new(prev_props), Hash.new(prev_state))
160+
self.run_callback(:after_update, prev_props, prev_state)
162161
State.update_states_to_observe
163162
end
164163
rescue Exception => e

0 commit comments

Comments
 (0)