reactive-ruby 0.7.32 → 0.7.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 212dc6ace47eb491a9464258c6df6e26e4c35579
4
- data.tar.gz: faa7ee755e54749e9acce87bc8c08ff1c890bc88
3
+ metadata.gz: 8a8e6fbd1897288817fe7b3abea0548784acb143
4
+ data.tar.gz: 9d89b9b4f0c398e450bb55117e1f6c2ef6ef64c4
5
5
  SHA512:
6
- metadata.gz: 4b721773a255f59e5a852788fd75a4fd2ab7340b9c8f8e5d0846ca009adf0d37150fb83010ad80810e203352467744f81cc10008c3daeff0b97898f1cacf8971
7
- data.tar.gz: 4b53af87056f9a2dbe19eddcd1217b7ab95daa705edb90011501702e956a97200dd28fff5e4396b30735c0344e408ee3b0cf8b7693294f6c01159307afbe5b15
6
+ metadata.gz: 4bf33cec30e4227dd94ff1fb453f625b40aa24fbb13201c30fa743e6529f2f768f4057174157402a9220ea2c165fefde5a1603ccdbb4ff8fec8edfffcf4e40b8
7
+ data.tar.gz: a3f22d4c8721d647f98f7e3eff04805fa6a6a5f80963edca8cbec9febb1c6ebf7c041b172668636b7314ee756e735674e56f247288acd7e2b74c540f4662e71e
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- reactive-ruby (0.7.31)
4
+ reactive-ruby (0.7.33)
5
5
  opal
6
6
  opal-activesupport (>= 0.2.0)
7
7
  opal-browser
data/README.md CHANGED
@@ -10,6 +10,8 @@
10
10
  It lets you write reactive UI components, with Ruby's elegance using the tried
11
11
  and true React.js engine. :heart:
12
12
 
13
+ [**Visit Our Documentation Site For The Full Story**](https://reactive-ruby.github.io)
14
+
13
15
  ### What's this Reactive Ruby?
14
16
 
15
17
  Reactive Ruby started as a fork of the original react.rb gem, and has since been
@@ -14,22 +14,6 @@ module React
14
14
  def self.included(base)
15
15
  base.include(API)
16
16
  base.include(React::Callbacks)
17
- base.instance_eval do
18
-
19
- class PropsWrapper
20
-
21
- def initialize(props_hash)
22
- @props_hash = props_hash
23
- @processed_params = {}
24
- end
25
-
26
- def [](prop)
27
- return unless @props_hash
28
- @props_hash[prop]
29
- end
30
-
31
- end
32
- end
33
17
  base.class_eval do
34
18
  class_attribute :initial_state
35
19
  define_callback :before_mount
@@ -102,11 +86,7 @@ module React
102
86
  unless name && name.method_defined?(:render)
103
87
  return super
104
88
  end
105
- if node_only
106
- React::RenderingContext.build { React::RenderingContext.render(name, *args, &block) }.to_n
107
- else
108
- React::RenderingContext.render(name, *args, &block)
109
- end
89
+ React::RenderingContext.build_or_render(node_only, name, *args, &block)
110
90
  end
111
91
 
112
92
  end
@@ -149,7 +129,7 @@ module React
149
129
 
150
130
  def component_will_mount
151
131
  IsomorphicHelpers.load_context(true) if IsomorphicHelpers.on_opal_client?
152
- @props_wrapper = self.class.const_get("PropsWrapper").new(Hash.new(`#{@native}.props`))
132
+ @props_wrapper = self.class.props_wrapper.new(Hash.new(`#{@native}.props`))
153
133
  set_state! initial_state if initial_state
154
134
  React::State.initialize_states(self, initial_state)
155
135
  React::State.set_state_context_to(self) { self.run_callback(:before_mount) }
@@ -202,7 +182,7 @@ module React
202
182
 
203
183
  def component_will_update(next_props, next_state)
204
184
  React::State.set_state_context_to(self) { self.run_callback(:before_update, Hash.new(next_props), Hash.new(next_state)) }
205
- @props_wrapper = self.class.const_get("PropsWrapper").new(Hash.new(next_props))
185
+ @props_wrapper = self.class.props_wrapper.new(Hash.new(next_props))
206
186
  rescue Exception => e
207
187
  self.class.process_exception(e, self)
208
188
  end
@@ -264,11 +244,7 @@ module React
264
244
  name = "p"
265
245
  end
266
246
 
267
- if node_only
268
- React::RenderingContext.build { React::RenderingContext.render(name, *args, &block) }.to_n
269
- else
270
- React::RenderingContext.render(name, *args, &block)
271
- end
247
+ React::RenderingContext.build_or_render(node_only, name, *args, &block)
272
248
  end
273
249
 
274
250
  def watch(value, &on_change)
@@ -28,7 +28,7 @@ module React
28
28
  end
29
29
 
30
30
  def validator
31
- @validator ||= React::Validator.new(self)
31
+ @validator ||= Validator.new(self)
32
32
  end
33
33
 
34
34
  def prop_types
@@ -55,44 +55,12 @@ module React
55
55
  validator.build(&block)
56
56
  end
57
57
 
58
- def define_param_method(name, param_type)
59
- wrapper = const_get("PropsWrapper")
60
- if param_type == React::Observable
61
- #(@two_way_params ||= []) << name
62
- wrapper.define_method("#{name}") do
63
- @props_hash[name].instance_variable_get("@value") if @props_hash[name]
64
- end
65
- wrapper.define_method("#{name}!") do |*args|
66
- return unless @props_hash[name]
67
- if args.count > 0
68
- current_value = @props_hash[name].instance_variable_get("@value")
69
- @props_hash[name].call args[0]
70
- current_value
71
- else
72
- current_value = @props_hash[name].instance_variable_get("@value")
73
- @props_hash[name].call current_value unless @dont_update_state rescue nil # rescue in case we in middle of render
74
- @props_hash[name]
75
- end
76
- end
77
- define_method("#{name}") { deprecated_params_method("#{name}") }
78
- define_method("#{name}!") { |*args| deprecated_params_method("#{name}!", *args) }
79
- elsif param_type == Proc
80
- wrapper.define_method("#{name}") do |*args, &block|
81
- @props_hash[name].call(*args, &block) if @props_hash[name]
82
- end
83
- define_method("#{name}") { deprecated_params_method("#{name}", *args, &block) }
84
- else
85
- wrapper.define_method("#{name}") do
86
- @processed_params[name] ||= if param_type.respond_to? :_react_param_conversion
87
- param_type._react_param_conversion @props_hash[name]
88
- elsif param_type.is_a?(Array) && param_type[0].respond_to?(:_react_param_conversion)
89
- @props_hash[name].collect { |param| param_type[0]._react_param_conversion param }
90
- else
91
- @props_hash[name]
92
- end
93
- end
94
- define_method("#{name}") { deprecated_params_method("#{name}") }
95
- end
58
+ def props_wrapper
59
+ @props_wrapper ||= Class.new(PropsWrapper)
60
+ end
61
+
62
+ def define_param(name, param_type)
63
+ props_wrapper.define_param(name, param_type, self)
96
64
  end
97
65
 
98
66
  def param(*args)
@@ -0,0 +1,65 @@
1
+ module React
2
+ module Component
3
+ class PropsWrapper < BasicObject
4
+ attr_reader :props
5
+
6
+ def self.define_param(name, param_type, owner)
7
+ owner.define_method("#{name}") do
8
+ deprecated_params_method("#{name}", *args, &block)
9
+ end
10
+ if param_type == React::Observable
11
+ owner.define_method("#{name}!") do |*args|
12
+ deprecated_params_method("#{name}!", *args)
13
+ end
14
+ define_method("#{name}") do
15
+ value_for(name)
16
+ end
17
+ define_method("#{name}!") do |*args|
18
+ current_value = value_for(name)
19
+ if args.count > 0
20
+ props[name].call args[0]
21
+ current_value
22
+ else
23
+ # rescue in case we in middle of render... What happens during a
24
+ # render that causes exception?
25
+ # Where does `dont_update_state` come from?
26
+ props[name].call current_value unless @dont_update_state rescue nil
27
+ props[name]
28
+ end
29
+ end
30
+ elsif param_type == Proc
31
+ define_method("#{name}") do |*args, &block|
32
+ props[name].call(*args, &block) if props[name]
33
+ end
34
+ else
35
+ define_method("#{name}") do
36
+ 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
43
+ else
44
+ props[name]
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ def initialize(props)
51
+ @props= props|| {}
52
+ end
53
+
54
+ def [](prop)
55
+ props[prop]
56
+ end
57
+
58
+ private
59
+
60
+ def value_for(name)
61
+ self[name].instance_variable_get("@value") if self[name]
62
+ end
63
+ end
64
+ end
65
+ end
@@ -34,11 +34,7 @@ module React
34
34
  unless name = const_get(name)
35
35
  return super
36
36
  end
37
- if node_only
38
- React::RenderingContext.build { React::RenderingContext.render(name, *args, &block) }.to_n
39
- else
40
- React::RenderingContext.render(name, *args, &block)
41
- end
37
+ React::RenderingContext.build_or_render(node_only, name, *args, &block)
42
38
  rescue
43
39
  end
44
40
 
@@ -4,6 +4,14 @@ module React
4
4
  attr_accessor :waiting_on_resources
5
5
  end
6
6
 
7
+ def self.build_or_render(node_only, name, *args, &block)
8
+ if node_only
9
+ React::RenderingContext.build { React::RenderingContext.render(name, *args, &block) }.to_n
10
+ else
11
+ React::RenderingContext.render(name, *args, &block)
12
+ end
13
+ end
14
+
7
15
  def self.render(name, *args, &block)
8
16
  remove_nodes_from_args(args)
9
17
  @buffer = [] unless @buffer
@@ -1,5 +1,6 @@
1
1
  module React
2
- class StateWrapper
2
+
3
+ class StateWrapper < BasicObject
3
4
 
4
5
  def initialize(native, from)
5
6
  @state_hash = Hash.new(`#{native}.state`)
@@ -130,17 +131,13 @@ module React
130
131
  @states ||= Hash.new { |h, k| h[k] = {} }
131
132
  end
132
133
 
133
- def new_observers
134
- @new_observers ||= Hash.new { |h, k| h[k] = Hash.new { |h, k| h[k] = [] } }
135
- end
136
-
137
- def current_observers
138
- @current_observers ||= Hash.new { |h, k| h[k] = Hash.new { |h, k| h[k] = [] } }
134
+ [:new_observers, :current_observers, :observers_by_name].each do |method_name|
135
+ define_method(method_name) do
136
+ instance_variable_get("@#{method_name}") or
137
+ instance_variable_set("@#{method_name}", Hash.new { |h, k| h[k] = Hash.new { |h, k| h[k] = [] } })
138
+ end
139
139
  end
140
140
 
141
- def observers_by_name
142
- @observers_by_name ||= Hash.new { |h, k| h[k] = Hash.new { |h, k| h[k] = [] } }
143
- end
144
141
  end
145
142
  end
146
143
  end
@@ -20,13 +20,11 @@ module React
20
20
  def requires(name, options = {})
21
21
  options[:required] = true
22
22
  define_rule(name, options)
23
- @component_class.define_param_method(name, options[:type])
24
23
  end
25
24
 
26
25
  def optional(name, options = {})
27
26
  options[:required] = false
28
27
  define_rule(name, options)
29
- @component_class.define_param_method(name, options[:type]) unless name == :params
30
28
  end
31
29
 
32
30
  def allow_undefined_props=(allow)
@@ -72,6 +70,7 @@ module React
72
70
 
73
71
  def define_rule(name, options = {})
74
72
  rules[name] = coerce_native_hash_values(options)
73
+ @component_class.define_param(name, options[:type]) unless name == :params
75
74
  end
76
75
 
77
76
  def errors
@@ -2,6 +2,7 @@ if RUBY_ENGINE == 'opal'
2
2
  require 'sources/react.js'
3
3
  require 'react/top_level'
4
4
  require 'react/component'
5
+ require 'react/component/props_wrapper'
5
6
  require 'react/component/base'
6
7
  require 'react/element'
7
8
  require 'react/event'
@@ -1,3 +1,3 @@
1
1
  module React
2
- VERSION = "0.7.32"
2
+ VERSION = "0.7.33"
3
3
  end
@@ -9,11 +9,10 @@ Gem::Specification.new do |s|
9
9
 
10
10
  s.author = 'David Chang'
11
11
  s.email = 'zeta11235813@gmail.com'
12
- s.homepage = 'https://github.com/zetachang/react.rb'
12
+ s.homepage = 'https://reactive-ruby.github.io'
13
13
  s.summary = 'Opal Ruby wrapper of React.js library.'
14
14
  s.license = 'MIT'
15
- s.description = "Write reactive UI component with Ruby's elegancy and compiled to run in Javascript."
16
-
15
+ s.description = "Write React UI components in pure Ruby."
17
16
  s.files = `git ls-files`.split("\n")
18
17
  s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
19
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -123,6 +123,17 @@ describe React::Component do
123
123
  expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<div>bar</div>')
124
124
  end
125
125
 
126
+ it 'allows kernal method names like "format" to be used as state variable names' do
127
+ Foo.class_eval do
128
+ before_mount do
129
+ state.format! 'yes'
130
+ state.foo! state.format
131
+ end
132
+ end
133
+
134
+ expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<div>yes</div>')
135
+ end
136
+
126
137
  it 'returns an observer with the bang method and no arguments' do
127
138
  Foo.class_eval do
128
139
  before_mount do
@@ -1,9 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  if opal?
4
-
5
4
  describe 'the param macro' do
6
-
7
5
  it "can create and access a required param" do
8
6
  stub_const 'Foo', Class.new(React::Component::Base)
9
7
  Foo.class_eval do
@@ -180,8 +178,6 @@ describe 'the param macro' do
180
178
  expect(React.render_to_static_markup(React.create_element(Foo, foo: observer))).to eq('<span>ha!</span>')
181
179
  expect(current_state).to eq("ha!")
182
180
  end
183
-
184
181
  end
185
-
186
182
  end
187
183
  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.32
4
+ version: 0.7.33
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-11-30 00:00:00.000000000 Z
11
+ date: 2015-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opal
@@ -136,8 +136,7 @@ dependencies:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
- description: Write reactive UI component with Ruby's elegancy and compiled to run
140
- in Javascript.
139
+ description: Write React UI components in pure Ruby.
141
140
  email: zeta11235813@gmail.com
142
141
  executables: []
143
142
  extensions: []
@@ -264,6 +263,7 @@ files:
264
263
  - lib/react/component/api.rb
265
264
  - lib/react/component/base.rb
266
265
  - lib/react/component/class_methods.rb
266
+ - lib/react/component/props_wrapper.rb
267
267
  - lib/react/element.rb
268
268
  - lib/react/event.rb
269
269
  - lib/react/ext/hash.rb
@@ -313,7 +313,7 @@ files:
313
313
  - spec/spec_helper.rb
314
314
  - spec/support/react/spec_helpers.rb
315
315
  - spec/vendor/es5-shim.min.js
316
- homepage: https://github.com/zetachang/react.rb
316
+ homepage: https://reactive-ruby.github.io
317
317
  licenses:
318
318
  - MIT
319
319
  metadata: {}