reactive-ruby 0.7.38 → 0.7.39

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 23600ed81f6cdbfd4492addb059c2fc226147f32
4
- data.tar.gz: 7ae2faaeacc75627e86614168cd7a79f250165a8
3
+ metadata.gz: 0cea406dc7bbeab7ecb30d5ce6656b560fa5e666
4
+ data.tar.gz: d9ff3e6794442ed3f443de03e4a2e84f611c4f32
5
5
  SHA512:
6
- metadata.gz: b56872543b2db22c8b3682de518415f84a7753c0402365cbf39679d13aa5e16d7c65ae756d92917646cd51283d05671aeef33d85e662a2e82ef63cd9c60991fc
7
- data.tar.gz: 787ef02379630312653277931881a916f8183f9998f634fb01545b78083102518e63de11fb120dcde63f70ac8ccdae318e8a7874410b2bd994316bb1dd9ebe33
6
+ metadata.gz: 41ee7e60bf8c39e39942e8d9976601f7f85ccb24835e3e2b013f94113ad469af2e9e283394f15ec7a558d8c5b3df474bff2dbe80657bb472f2e20ddf27055af3
7
+ data.tar.gz: 49a1603e9b00ee55bd9f4c4b4781031250e7c35c24c3485aeefb4063ad65f6198b862f4aed7bf6d0693df37766b2401dff6b05cea866e978102ea85f66fad376
@@ -179,7 +179,7 @@ module React
179
179
 
180
180
  def component_will_update(next_props, next_state)
181
181
  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))
182
+ @props_wrapper = self.class.props_wrapper.new(Hash.new(next_props), @props_wrapper)
183
183
  rescue Exception => e
184
184
  self.class.process_exception(e, self)
185
185
  end
@@ -33,23 +33,39 @@ module React
33
33
  end
34
34
  else
35
35
  define_method("#{name}") do
36
- @processed_params[name] ||= if param_type.respond_to? :_react_param_conversion
37
- param_type._react_param_conversion props[name]
38
- elsif param_type.is_a?(Array) &&
39
- param_type[0].respond_to?(:_react_param_conversion)
40
- props[name].collect do |param|
41
- param_type[0]._react_param_conversion param
42
- end
36
+ if @processed_params.has_key? name
37
+ @processed_params[name]
43
38
  else
44
- props[name]
39
+ @processed_params[name] = if param_type.respond_to? :_react_param_conversion
40
+ param_type._react_param_conversion props[name]
41
+ elsif param_type.is_a?(Array) &&
42
+ param_type[0].respond_to?(:_react_param_conversion)
43
+ props[name].collect do |param|
44
+ param_type[0]._react_param_conversion param
45
+ end
46
+ else
47
+ props[name]
48
+ end
45
49
  end
46
50
  end
47
51
  end
48
52
  end
49
53
 
50
- def initialize(props)
54
+ def unchanged_processed_params(new_props)
55
+ Hash[
56
+ *@processed_params.collect do |key, value|
57
+ [key, value] if @props[key] == new_props[key]
58
+ end.compact.flatten(1)
59
+ ]
60
+ end
61
+
62
+ def initialize(props, current_props_wrapper=nil)
51
63
  @props = props || {}
52
- @processed_params = {}
64
+ @processed_params = if current_props_wrapper
65
+ current_props_wrapper.unchanged_processed_params(props)
66
+ else
67
+ {}
68
+ end
53
69
  end
54
70
 
55
71
  def [](prop)
@@ -1,3 +1,3 @@
1
1
  module React
2
- VERSION = "0.7.38"
2
+ VERSION = "0.7.39"
3
3
  end
@@ -195,25 +195,55 @@ describe 'the param macro' do
195
195
  expect(`window.dummy_log`).to eq(["Warning: Failed propType: In component `Foo`\nProvided prop `foo` could not be converted to BazWoggle"])
196
196
  end
197
197
 
198
- it "can will only convert once" do
199
- stub_const "BazWoggle", Class.new
200
- BazWoggle.class_eval do
201
- def initialize(kind)
202
- @kind = kind
198
+ describe "converts params only once" do
199
+
200
+ it "not on every access" do
201
+ stub_const "BazWoggle", Class.new
202
+ BazWoggle.class_eval do
203
+ def initialize(kind)
204
+ @kind = kind
205
+ end
206
+ attr_accessor :kind
207
+ def self._react_param_conversion(json, validate_only)
208
+ new(json[:bazwoggle]) if json[:bazwoggle]
209
+ end
203
210
  end
204
- attr_accessor :kind
205
- def self._react_param_conversion(json, validate_only)
206
- new(json[:bazwoggle]) if json[:bazwoggle]
211
+ Foo.class_eval do
212
+ param :foo, type: BazWoggle
213
+ def render
214
+ params.foo.kind = params.foo.kind+1
215
+ "#{params.foo.kind}"
216
+ end
207
217
  end
218
+ expect(React.render_to_static_markup(React.create_element(Foo, foo: {bazwoggle: 1}))).to eq('<span>2</span>')
208
219
  end
209
- Foo.class_eval do
210
- param :foo, type: BazWoggle
211
- def render
212
- params.foo.kind = params.foo.kind+1
213
- "#{params.foo.kind}"
220
+
221
+ it "not after state update" do
222
+ stub_const "BazWoggle", Class.new
223
+ BazWoggle.class_eval do
224
+ def initialize(kind)
225
+ @kind = kind
226
+ end
227
+ attr_accessor :kind
228
+ def self._react_param_conversion(json, validate_only)
229
+ new(json[:bazwoggle]) if json[:bazwoggle]
230
+ end
231
+ end
232
+ Foo.class_eval do
233
+ param :foo, type: BazWoggle
234
+ export_state :change_me
235
+ before_mount do
236
+ params.foo.kind = params.foo.kind+1
237
+ end
238
+ def render
239
+ "#{params.foo.kind} - #{Foo.change_me}"
240
+ end
214
241
  end
242
+ div = `document.createElement("div")`
243
+ React.render(React.create_element(Foo, foo: {bazwoggle: 1}), div)
244
+ Foo.change_me! "updated"
245
+ expect(`div.children[0].innerHTML`).to eq("2 - updated")
215
246
  end
216
- expect(React.render_to_static_markup(React.create_element(Foo, foo: {bazwoggle: 1}))).to eq('<span>2</span>')
217
247
  end
218
248
 
219
249
  it "will alias a Proc type param" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reactive-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.38
4
+ version: 0.7.39
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Chang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-30 00:00:00.000000000 Z
11
+ date: 2016-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opal