reactive-ruby 0.7.19 → 0.7.20

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: 1291eb9025b7407c477b96834fdafb03417f74b4
4
- data.tar.gz: 8a9c2c6290d2470b8160e42b8dd5d55edd1e38e7
3
+ metadata.gz: 9ca98468e40f18b1764978546a1a3436390ebc84
4
+ data.tar.gz: 70b9057c1a7924574a881d312c62551a8cb72adb
5
5
  SHA512:
6
- metadata.gz: 60717270fb07ccda56cf87360442bb5991c68cecf206041f4f4b057e2d303b58e216a943a5dddae29ed7214555034eff372f7cb60159b92f5ed8a79751768b4e
7
- data.tar.gz: 630c92fd6d7cdacad40602624292bec149edf94e50a5aa2bdbb5b4183a392bd48a84b3120308cdb755a50e719ffe30b2f807a2203ecf3bf292d31956f69a9d34
6
+ metadata.gz: b6800c763a8cc32f967fd89277eb9f365de027ec052feae35facd86f06a155e2173f90b5e636f97bb12bda4936ed27b1f25ad5da3dd749608a10d2166a5f4f20
7
+ data.tar.gz: ea5cc3ffdee3bbbfb778833338392e598de397638a7b48df10dedd3bfed61c7ddebe514dea54edbd0d16d9547c6e072720b655c3911e98207b2a52045a52da59
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../..
3
3
  specs:
4
- reactive-ruby (0.7.18)
4
+ reactive-ruby (0.7.19)
5
5
  opal
6
6
  opal-activesupport
7
7
  opal-browser
@@ -0,0 +1,72 @@
1
+ class Rerendering
2
+
3
+ include React::Component
4
+
5
+ class Child
6
+
7
+ include React::Component
8
+
9
+ define_state state_changes: 0
10
+ require_param :param
11
+
12
+ before_mount do
13
+ @render_count = 0
14
+ @render_difference = -1
15
+ @render_saves = []
16
+ end
17
+
18
+ after_mount do
19
+ @start_time = Time.now.to_i
20
+ every(7) { puts "state changes actual ticks = #{Time.now.to_i-@start_time}, calculated = #{(state_changes+1)*7}"; state_changes! state_changes+1}
21
+ end
22
+
23
+ def render
24
+ puts "child rendering"
25
+ @render_count = @render_count+1
26
+ puts "ticks = #{(state_changes)*7} / #{(param)*11} / #{(Rerendering.exported_state_changes)*12}"
27
+ if param + state_changes + Rerendering.exported_state_changes != @render_count + @render_difference
28
+ @render_difference = param + state_changes + Rerendering.exported_state_changes - @render_count
29
+ save = "Skipped a render @ #{Time.now.to_i-@start_time} secs when param = #{param} * 11, state_changes = #{state_changes} * 7, exported = #{Rerendering.exported_state_changes} * 12"
30
+ @render_saves << save
31
+ puts save
32
+ end
33
+ table do
34
+ tr { "ticks = #{(state_changes)*7} / #{(param)*11} / #{(Rerendering.exported_state_changes)*12}".td(col_span: 3) }
35
+ @render_saves.each do |save|
36
+ tr { save.td(col_span: 3) }
37
+ end
38
+ tr { "child param has changed".td; param.td; "times.".td }
39
+ tr { "internal state has changed".td; state_changes.td; "times.".td }
40
+ tr { "external state has changed".td; Rerendering.exported_state_changes.td; "times.".td }
41
+ tr { "that's a total of".td; (param + state_changes + Rerendering.exported_state_changes).td; "changes".td }
42
+ tr { "And I have rendered a total of".td; (@render_count).td; "times".td }
43
+ end
44
+ end
45
+
46
+ end
47
+
48
+ define_state parent_state_changes: 0
49
+ define_state param_changes: 0
50
+ export_state exported_state_changes: 0
51
+
52
+ before_mount do
53
+ @render_count = 0
54
+ end
55
+
56
+ after_mount do
57
+ start_time = Time.now.to_i
58
+ every(5) { parent_state_changes! parent_state_changes+1 }
59
+ every(11) { puts "param changes actual ticks = #{Time.now.to_i-start_time}, calculated = #{(param_changes+1)*11}"; param_changes! param_changes+1 }
60
+ every(12) { puts "export changes actual ticks = #{Time.now.to_i-start_time}, calculated = #{(exported_state_changes+1)*11}"; exported_state_changes! exported_state_changes + 1 }
61
+ end
62
+
63
+ def render
64
+ puts "master_rendering"
65
+ @render_count = @render_count+1
66
+ div do
67
+ "master has changed state a total of #{parent_state_changes + param_changes} times, and has rendered #{@render_count} times".br
68
+ Child(param: param_changes)
69
+ end
70
+ end
71
+
72
+ end
@@ -9,6 +9,7 @@ require 'reactive-router'
9
9
  require 'basics'
10
10
  require 'reuse'
11
11
  require 'items'
12
+ require 'rerendering'
12
13
 
13
14
 
14
15
  class Show
@@ -20,6 +21,7 @@ class Show
20
21
  routes(path: "/") do
21
22
  route(path: "basics", name: "basics", handler: Basics)
22
23
  route(path: "reuse", name: "reuse", handler: Reuse)
24
+ route(path: "rerendering", name: "rerendering", handler: Rerendering)
23
25
  redirect(from: "/", to: "basics")
24
26
  end
25
27
 
@@ -29,6 +31,7 @@ class Show
29
31
  div do
30
32
  link(to: "basics") { "Basics" }; br
31
33
  link(to: "reuse") { "Reusable Components" }; br
34
+ link(to: "rerendering") { "Rerendering Test" }; br
32
35
  end
33
36
  route_handler
34
37
  end
@@ -63,23 +63,17 @@ module React
63
63
  base.extend(ClassMethods)
64
64
 
65
65
  if base.name
66
- #puts "getting parent of #{base.name}"
67
66
  parent = base.name.split("::").inject([Module]) { |nesting, next_const| nesting + [nesting.last.const_get(next_const)] }[-2]
68
- #puts "defining method missing for module #{parent}"
69
-
70
- class << parent #.class_eval do
71
-
72
67
 
68
+ class << parent
73
69
 
74
70
  def method_missing(n, *args, &block)
75
- #puts "method missing for #{n} called"
76
71
  name = n
77
72
  if name =~ /_as_node$/
78
73
  node_only = true
79
74
  name = name.gsub(/_as_node$/, "")
80
75
  end
81
76
  unless name = const_get(name) and name.method_defined? :render
82
- #puts "can't find render method"
83
77
  return super
84
78
  end
85
79
  if node_only
@@ -114,7 +108,7 @@ module React
114
108
  end
115
109
 
116
110
  def update_react_js_state(object, name, value)
117
- set_state({"#{object.class.to_s+'.' unless object == self}name" => value}) rescue nil
111
+ set_state({"***_state_updated_at-***" => Time.now.to_f, "#{object.class.to_s+'.' unless object == self}#{name}" => value}) rescue nil
118
112
  end
119
113
 
120
114
  def emit(event_name, *args)
@@ -148,10 +142,30 @@ module React
148
142
  self.class.process_exception(e, self)
149
143
  end
150
144
 
145
+ def props_changed?(next_props)
146
+ return true unless params.keys.sort == next_props.keys.sort
147
+ params.detect { |k, v| `#{next_props[k]} != #{params[k]}`}
148
+ end
149
+
151
150
  def should_component_update?(next_props, next_state)
152
- React::State.set_state_context_to(self) { self.respond_to?(:needs_update?) ? self.needs_update?(Hash.new(next_props), Hash.new(next_state)) : true }
153
- rescue Exception => e
154
- self.class.process_exception(e, self)
151
+ React::State.set_state_context_to(self) do
152
+ next_props = Hash.new(next_props)
153
+ if self.respond_to?(:needs_update?)
154
+ !!self.needs_update?(next_props, Hash.new(next_state))
155
+ elsif false # switch to true to force updates per standard react
156
+ true
157
+ elsif props_changed? next_props
158
+ true
159
+ elsif `!next_state != !#{@native}.state`
160
+ true
161
+ elsif `!next_state && !#{@native}.state`
162
+ false
163
+ elsif `next_state["***_state_updated_at-***"] != #{@native}.state["***_state_updated_at-***"]`
164
+ true
165
+ else
166
+ false
167
+ end.to_n
168
+ end
155
169
  end
156
170
 
157
171
  def component_will_update(next_props, next_state)
@@ -247,12 +261,12 @@ module React
247
261
  module ClassMethods
248
262
 
249
263
  def backtrace(*args)
250
- @backtrace_on = (args.count == 0 or (args[0] != :off and args[0]))
264
+ @backtrace_off = (args[0] == :off)
251
265
  end
252
266
 
253
267
  def process_exception(e, component, reraise = nil)
254
268
  message = ["Exception raised while rendering #{component}"]
255
- if @backtrace_on
269
+ if !@backtrace_off
256
270
  message << " #{e.backtrace[0]}"
257
271
  message += e.backtrace[1..-1].collect { |line| line }
258
272
  else
@@ -72,11 +72,22 @@ module React
72
72
  end
73
73
 
74
74
  def set_state_context_to(observer) # wrap all execution that may set or get states in a block so we know which observer is executing
75
+ if `typeof window.reactive_ruby_timing !== 'undefined'`
76
+ @nesting_level = (@nesting_level || 0) + 1
77
+ start_time = Time.now.to_f
78
+ observer_name = (observer.class.respond_to?(:name) ? observer.class.name : observer.to_s) rescue "object:#{observer.object_id}"
79
+ puts "#{' ' * @nesting_level} Timing #{observer_name} Execution"
80
+ end
75
81
  saved_current_observer = @current_observer
76
82
  @current_observer = observer
77
83
  return_value = yield
84
+ if `typeof window.reactive_ruby_timing !== 'undefined'`
85
+ puts "#{' ' * @nesting_level} Timing #{observer_name} Completed in #{'%.04f' % (Time.now.to_f-start_time)} seconds"
86
+ end
87
+ return_value
78
88
  ensure
79
89
  @current_observer = saved_current_observer
90
+ @nesting_level = [0, @nesting_level - 1].max if `typeof window.reactive_ruby_timing !== 'undefined'`
80
91
  return_value
81
92
  end
82
93
 
@@ -1,3 +1,3 @@
1
1
  module React
2
- VERSION = "0.7.19"
2
+ VERSION = "0.7.20"
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.19
4
+ version: 0.7.20
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-24 00:00:00.000000000 Z
11
+ date: 2015-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opal
@@ -99,6 +99,7 @@ files:
99
99
  - example/examples/app/items.rb
100
100
  - example/examples/app/jquery.js
101
101
  - example/examples/app/react-router.js
102
+ - example/examples/app/rerendering.rb
102
103
  - example/examples/app/reuse.rb
103
104
  - example/examples/app/show.rb
104
105
  - example/examples/config.ru