reactive-ruby 0.7.17 → 0.7.18

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: 29fbf083f6ff7680077ff9123a55f40b3212b9e1
4
- data.tar.gz: 539e46aaf607d86f535e6ed7f3a78a12188e00e9
3
+ metadata.gz: 2bb53545fea7cc396c074b19f9b6ea356cb75e3f
4
+ data.tar.gz: 0219c73e5aa24c6b43ffaa1349555f422029121d
5
5
  SHA512:
6
- metadata.gz: dc3ce82f056121c1ebf795eca5e4d2b165e489d6bb148711599f258e9165aaf9c431cfcc6c578042beb10455670cd9fad4889939934d2c57791d603888fd9402
7
- data.tar.gz: 504baa1e1fe8118e848b336758a3ead39a87f3b36a2f044c6d18e74041553e528ea7e9c6de93cde832d70c9cd1bec888d08a4fbae167d33e1d95ae9edc7ef071
6
+ metadata.gz: 6edeec42272d3fd8d32d15366c04473c8cd1be7903cabe4b2f4f40d21a3d6fa3eda38bee50420b785cd1261cf3b4dd33b0b1f97b79b3785c139b7a97f28ecaae
7
+ data.tar.gz: 259820d440ffce2e671bbfcd40b0f990c7cad408d795f27efaa5cd4d7717eb4b6422ced7261153adcb548cf157cf2f4ea988f8af4dccee92d0f4d581e2577013
@@ -10,7 +10,7 @@ require 'native'
10
10
 
11
11
  module React
12
12
  module Component
13
-
13
+
14
14
  def self.included(base)
15
15
  base.include(API)
16
16
  base.include(React::Callbacks)
@@ -22,11 +22,11 @@ module React
22
22
  define_callback :before_update
23
23
  define_callback :after_update
24
24
  define_callback :before_unmount
25
-
25
+
26
26
  def render
27
27
  raise "no render defined"
28
28
  end unless method_defined? :render
29
-
29
+
30
30
  def children
31
31
  nodes = `#{@native}.props.children` || []
32
32
  class << nodes
@@ -58,23 +58,23 @@ module React
58
58
 
59
59
  nodes
60
60
  end
61
-
61
+
62
62
  end
63
63
  base.extend(ClassMethods)
64
-
64
+
65
65
  if base.name
66
66
  #puts "getting parent of #{base.name}"
67
- parent = base.name.split("::").inject([Module]) { |nesting, next_const| nesting + [nesting.last.const_get(next_const)] }[-2]
67
+ parent = base.name.split("::").inject([Module]) { |nesting, next_const| nesting + [nesting.last.const_get(next_const)] }[-2]
68
68
  #puts "defining method missing for module #{parent}"
69
69
 
70
70
  class << parent #.class_eval do
71
-
72
-
71
+
72
+
73
73
 
74
74
  def method_missing(n, *args, &block)
75
75
  #puts "method missing for #{n} called"
76
76
  name = n
77
- if name =~ /_as_node$/
77
+ if name =~ /_as_node$/
78
78
  node_only = true
79
79
  name = name.gsub(/_as_node$/, "")
80
80
  end
@@ -92,7 +92,7 @@ module React
92
92
  message = "#{base.name}.#{n} method_missing handler exception raised: #{e}"
93
93
  `console.error(#{message})`
94
94
  end
95
-
95
+
96
96
  end
97
97
  end
98
98
  end
@@ -100,7 +100,7 @@ module React
100
100
  def initialize(native_element)
101
101
  @native = native_element
102
102
  end
103
-
103
+
104
104
  def params
105
105
  Hash.new(`#{@native}.props`)
106
106
  end
@@ -113,9 +113,9 @@ module React
113
113
  raise "No native ReactComponent associated" unless @native
114
114
  Hash.new(`#{@native}.state`)
115
115
  end
116
-
116
+
117
117
  def update_react_js_state(object, name, value)
118
- set_state({"#{object.class.to_s+'.' unless object == self}name" => value}) rescue nil # in case we are in render
118
+ set_state({"#{object.class.to_s+'.' unless object == self}name" => value}) rescue nil
119
119
  end
120
120
 
121
121
  def emit(event_name, *args)
@@ -133,7 +133,7 @@ module React
133
133
 
134
134
  def component_did_mount
135
135
  React::State.set_state_context_to(self) do
136
- self.run_callback(:after_mount)
136
+ self.run_callback(:after_mount)
137
137
  React::State.update_states_to_observe
138
138
  end
139
139
  rescue Exception => e
@@ -160,7 +160,7 @@ module React
160
160
  rescue Exception => e
161
161
  self.class.process_exception(e, self)
162
162
  end
163
-
163
+
164
164
 
165
165
  def component_did_update(prev_props, prev_state)
166
166
  React::State.set_state_context_to(self) do
@@ -172,7 +172,7 @@ module React
172
172
  end
173
173
 
174
174
  def component_will_unmount
175
- React::State.set_state_context_to(self) do
175
+ React::State.set_state_context_to(self) do
176
176
  self.run_callback(:before_unmount)
177
177
  React::State.remove
178
178
  end
@@ -187,12 +187,12 @@ module React
187
187
  Kernel.p(*args)
188
188
  end
189
189
  end
190
-
190
+
191
191
  def component?(name)
192
192
  name_list = name.split("::")
193
193
  scope_list = self.class.name.split("::").inject([Module]) { |nesting, next_const| nesting + [nesting.last.const_get(next_const)] }.reverse
194
194
  scope_list.each do |scope|
195
- component = name_list.inject(scope) do |scope, class_name|
195
+ component = name_list.inject(scope) do |scope, class_name|
196
196
  scope.const_get(class_name)
197
197
  end rescue nil
198
198
  return component if component and component.method_defined? :render
@@ -203,7 +203,7 @@ module React
203
203
  def method_missing(n, *args, &block)
204
204
  return params[n] if params.key? n
205
205
  name = n
206
- if name =~ /_as_node$/
206
+ if name =~ /_as_node$/
207
207
  node_only = true
208
208
  name = name.gsub(/_as_node$/, "")
209
209
  end
@@ -211,32 +211,32 @@ module React
211
211
  return super
212
212
  end
213
213
 
214
- if name == "present"
214
+ if name == "present"
215
215
  name = args.shift
216
216
  end
217
217
 
218
218
  if name == "_p_tag"
219
219
  name = "p"
220
220
  end
221
-
222
- if node_only
221
+
222
+ if node_only
223
223
  React::RenderingContext.build { React::RenderingContext.render(name, *args, &block) }.to_n
224
224
  else
225
225
  React::RenderingContext.render(name, *args, &block)
226
226
  end
227
-
227
+
228
228
  end
229
-
229
+
230
230
  def watch(value, &on_change)
231
231
  React::Observable.new(value, on_change)
232
232
  end
233
-
233
+
234
234
  def define_state(*args, &block)
235
235
  React::State.initialize_states(self, self.class.define_state(*args, &block))
236
236
  end
237
-
237
+
238
238
  attr_reader :waiting_on_resources
239
-
239
+
240
240
  def _render_wrapper
241
241
  React::State.set_state_context_to(self) do
242
242
  RenderingContext.render(nil) {render || ""}.tap { |element| @waiting_on_resources = element.waiting_on_resources if element.respond_to? :waiting_on_resources }
@@ -246,16 +246,16 @@ module React
246
246
  end
247
247
 
248
248
  module ClassMethods
249
-
249
+
250
250
  def backtrace(*args)
251
251
  @backtrace_on = (args.count == 0 or (args[0] != :off and args[0]))
252
252
  end
253
-
253
+
254
254
  def process_exception(e, component, reraise = nil)
255
255
  message = ["Exception raised while rendering #{component}"]
256
256
  if @backtrace_on
257
257
  message << " #{e.backtrace[0]}"
258
- message += e.backtrace[1..-1].collect { |line| line }
258
+ message += e.backtrace[1..-1].collect { |line| line }
259
259
  else
260
260
  message[0] += ": #{e.message}"
261
261
  end
@@ -263,11 +263,11 @@ module React
263
263
  `console.error(message)`
264
264
  raise e if reraise
265
265
  end
266
-
266
+
267
267
  def validator
268
268
  @validator ||= React::Validator.new
269
269
  end
270
-
270
+
271
271
  def prop_types
272
272
  if self.validator
273
273
  {
@@ -291,7 +291,7 @@ module React
291
291
  def params(&block)
292
292
  validator.build(&block)
293
293
  end
294
-
294
+
295
295
  def define_param_method(name, param_type)
296
296
  if param_type == React::Observable
297
297
  (@two_way_params ||= []) << name
@@ -325,27 +325,27 @@ module React
325
325
  end
326
326
  end
327
327
  end
328
-
328
+
329
329
  def required_param(name, options = {})
330
330
  validator.requires(name, options)
331
331
  define_param_method(name, options[:type])
332
332
  end
333
-
333
+
334
334
  alias_method :require_param, :required_param
335
-
335
+
336
336
  def optional_param(name, options = {})
337
337
  validator.optional(name, options)
338
338
  define_param_method(name, options[:type]) unless name == :params
339
- end
340
-
339
+ end
340
+
341
341
  def collect_other_params_as(name)
342
342
  validator.all_others(name)
343
343
  define_method(name) do
344
344
  @_all_others ||= self.class.validator.collect_all_others(params)
345
345
  end
346
346
  end
347
-
348
- def define_state(*states, &block)
347
+
348
+ def define_state(*states, &block)
349
349
  default_initial_value = (block and block.arity == 0) ? yield : nil
350
350
  states_hash = (states.last.is_a? Hash) ? states.pop : {}
351
351
  states.each { |name| states_hash[name] = default_initial_value }
@@ -354,8 +354,8 @@ module React
354
354
  define_state_methods(self, name, &block)
355
355
  end
356
356
  end
357
-
358
- def export_state(*states, &block)
357
+
358
+ def export_state(*states, &block)
359
359
  default_initial_value = (block and block.arity == 0) ? yield : nil
360
360
  states_hash = (states.last.is_a? Hash) ? states.pop : {}
361
361
  states.each { |name| states_hash[name] = default_initial_value }
@@ -365,7 +365,7 @@ module React
365
365
  define_state_methods(singleton_class, name, self, &block)
366
366
  end
367
367
  end
368
-
368
+
369
369
  def define_state_methods(this, name, from = nil, &block)
370
370
  this.define_method("#{name}") do
371
371
  React::State.get_state(from || self, name)
@@ -385,36 +385,36 @@ module React
385
385
  current_state = React::State.get_state(from || self, name)
386
386
  yield name, React::State.get_state(from || self, name), current_state if block and block.arity > 0
387
387
  React::State.set_state(from || self, name, current_state)
388
- React::Observable.new(current_state) do |new_value|
388
+ React::Observable.new(current_state) do |new_value|
389
389
  yield name, React::State.get_state(from || self, name), new_value if block and block.arity > 0
390
390
  React::State.set_state(from || self, name, new_value)
391
391
  end
392
392
  end
393
393
  end
394
394
  end
395
-
395
+
396
396
  def native_mixin(item)
397
397
  native_mixins << item
398
398
  end
399
-
399
+
400
400
  def native_mixins
401
401
  @native_mixins ||= []
402
402
  end
403
-
403
+
404
404
  def static_call_back(name, &block)
405
405
  static_call_backs[name] = block
406
406
  end
407
-
407
+
408
408
  def static_call_backs
409
409
  @static_call_backs ||= {}
410
410
  end
411
-
411
+
412
412
  def export_component(opts = {})
413
413
  export_name = (opts[:as] || name).split("::")
414
414
  first_name = export_name.first
415
415
  Native(`window`)[first_name] = add_item_to_tree(Native(`window`)[first_name], [React::API.create_native_react_class(self)] + export_name[1..-1].reverse).to_n
416
416
  end
417
-
417
+
418
418
  def add_item_to_tree(current_tree, new_item)
419
419
  if Native(current_tree).class != Native::Object or new_item.length == 1
420
420
  new_item.inject do |memo, sub_name| {sub_name => memo} end
@@ -423,7 +423,7 @@ module React
423
423
  current_tree
424
424
  end
425
425
  end
426
-
426
+
427
427
  end
428
428
 
429
429
  module API
@@ -469,6 +469,6 @@ module React
469
469
  }
470
470
  end
471
471
  end
472
-
472
+
473
473
  end
474
474
  end
@@ -1,33 +1,46 @@
1
1
  module React
2
-
2
+
3
3
  class State
4
-
4
+
5
5
  class << self
6
-
6
+
7
7
  attr_reader :current_observer
8
-
8
+
9
9
  def initialize_states(object, initial_values) # initialize objects' name/value pairs
10
10
  states[object].merge!(initial_values || {})
11
11
  end
12
12
 
13
- def get_state(object, name, current_observer = @current_observer)
13
+ def get_state(object, name, current_observer = @current_observer)
14
14
  # get current value of name for object, remember that the current object depends on this state, current observer can be overriden with last param
15
15
  new_observers[current_observer][object] << name if current_observer and !new_observers[current_observer][object].include? name
16
16
  states[object][name]
17
17
  end
18
18
 
19
- def set_state(object, name, value) # set object's name state to value, tell all observers it has changed. Observers must implement update_react_js_state
20
- states[object][name] = value
19
+ def set_state2(object, name, value) # set object's name state to value, tell all observers it has changed. Observers must implement update_react_js_state
21
20
  observers_by_name[object][name].dup.each do |observer|
22
21
  observer.update_react_js_state(object, name, value)
23
22
  end
23
+ end
24
+
25
+ def set_state(object, name, value)
26
+ states[object][name] = value
27
+ if name == "!CHANGED!" and @current_observer
28
+ puts "changing !CHANGED! to #{value} with a current observer - actual change will be delayed"
29
+ after(0.01) do
30
+ value = "#{value}@#{Time.now}"
31
+ puts "NOW setting !CHANGED! to #{value}"
32
+ set_state2(object, name, value)
33
+ end
34
+ else
35
+ set_state2(object, name, value)
36
+ end
24
37
  value
25
38
  end
26
-
39
+
27
40
  def will_be_observing?(object, name, current_observer)
28
41
  current_observer and new_observers[current_observer][object].include?(name)
29
42
  end
30
-
43
+
31
44
  def is_observing?(object, name, current_observer)
32
45
  current_observer and observers_by_name[object][name].include?(current_observer)
33
46
  end
@@ -35,7 +48,7 @@ module React
35
48
  def update_states_to_observe(current_observer = @current_observer) # should be called after the last after_render callback, currently called after components render method
36
49
  raise "update_states_to_observer called outside of watch block" unless current_observer
37
50
  current_observers[current_observer].each do |object, names|
38
- names.each do |name|
51
+ names.each do |name|
39
52
  observers_by_name[object][name].delete(current_observer)
40
53
  end
41
54
  end
@@ -47,11 +60,11 @@ module React
47
60
  end
48
61
  end
49
62
  end
50
-
63
+
51
64
  def remove # call after component is unmounted
52
65
  raise "remove called outside of watch block" unless @current_observer
53
66
  current_observers[@current_observer].each do |object, names|
54
- names.each do |name|
67
+ names.each do |name|
55
68
  observers_by_name[object][name].delete(@current_observer)
56
69
  end
57
70
  end
@@ -66,25 +79,25 @@ module React
66
79
  @current_observer = saved_current_observer
67
80
  return_value
68
81
  end
69
-
82
+
70
83
  def states
71
- @states ||= Hash.new { |h, k| h[k] = {} }
84
+ @states ||= Hash.new { |h, k| h[k] = {} }
72
85
  end
73
-
86
+
74
87
  def new_observers
75
88
  @new_observers ||= Hash.new { |h, k| h[k] = Hash.new { |h, k| h[k] = [] } }
76
89
  end
77
-
90
+
78
91
  def current_observers
79
92
  @current_observers ||= Hash.new { |h, k| h[k] = Hash.new { |h, k| h[k] = [] } }
80
93
  end
81
-
94
+
82
95
  def observers_by_name
83
96
  @observers_by_name ||= Hash.new { |h, k| h[k] = Hash.new { |h, k| h[k] = [] } }
84
97
  end
85
-
98
+
86
99
  end
87
-
100
+
88
101
  end
89
-
90
- end
102
+
103
+ end
@@ -1,3 +1,3 @@
1
1
  module React
2
- VERSION = "0.7.17"
2
+ VERSION = "0.7.18"
3
3
  end
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.17
4
+ version: 0.7.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Chang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-15 00:00:00.000000000 Z
11
+ date: 2015-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opal