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

Commit 0700a46

Browse files
committed
let the props wrapper live!
1 parent 9a00632 commit 0700a46

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

lib/react/component.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def each(&block)
9696
end
9797

9898
def params
99-
@props_wrapper
99+
@params ||= self.class.props_wrapper.new(self)
100100
end
101101

102102
def props
@@ -126,7 +126,6 @@ def emit(event_name, *args)
126126

127127
def component_will_mount
128128
IsomorphicHelpers.load_context(true) if IsomorphicHelpers.on_opal_client?
129-
@props_wrapper = self.class.props_wrapper.new(Hash.new(`#{@native}.props`))
130129
set_state! initial_state if initial_state
131130
State.initialize_states(self, initial_state)
132131
State.set_state_context_to(self) { self.run_callback(:before_mount) }
@@ -179,7 +178,6 @@ def should_component_update?(next_props, next_state)
179178

180179
def component_will_update(next_props, next_state)
181180
State.set_state_context_to(self) { self.run_callback(:before_update, Hash.new(next_props), Hash.new(next_state)) }
182-
@props_wrapper = self.class.props_wrapper.new(Hash.new(next_props))
183181
rescue Exception => e
184182
self.class.process_exception(e, self)
185183
end

lib/react/component/props_wrapper.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module React
22
module Component
33
class PropsWrapper
4-
attr_reader :props
4+
attr_reader :owner
55

66
def self.define_param(name, param_type)
77
if param_type == Observable
@@ -41,8 +41,8 @@ def self.define_param(name, param_type)
4141
end
4242
end
4343

44-
def initialize(props)
45-
@props = props || {}
44+
def initialize(owner)
45+
@owner = owner
4646
end
4747

4848
def [](prop)
@@ -51,6 +51,10 @@ def [](prop)
5151

5252
private
5353

54+
def props
55+
owner.props
56+
end
57+
5458
def value_for(name)
5559
self[name].instance_variable_get("@value") if self[name]
5660
end

0 commit comments

Comments
 (0)