reactive-router 0.7.4 → 0.7.5

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: 4a37cfefc5d18c03f42d0302fd1e56360ab0acdf
4
- data.tar.gz: c367a01366dca24fed30dfa4bbf332d7b6e83163
3
+ metadata.gz: afcd6107bb9240daef9cfd61b79857b40dc92bd1
4
+ data.tar.gz: 63feb3be11e99dffb41553252d290efbc9d37741
5
5
  SHA512:
6
- metadata.gz: 84257330b586a80d5d958207e31f2797bf95e4ee8538c4ffd4fd1bc80f8c47b93302ef1b1eb9c10da86e6500ad5a34d90c7e2b9c60eb107cf6f523359528f157
7
- data.tar.gz: 5d130e422da66bcbc0ed5f3bd7c89f69c312349de727086fe26ab41fdae9019c27203794cf4ccd997cc16b18ab65bb76556e3f084de4e55de8bc7c0e6c7d6b69
6
+ metadata.gz: e0f20cfccd6e0ac4276b8422d5ef49f4ed07d064f5de209ad825b60e59c3d9dfc1f88518268aa068d9f467384a6ee8b28283192c9d98890e28c6c91832df3567
7
+ data.tar.gz: 4d5322c6bb0a294f0e5e9af3ec06cf44d780158711873739d9775ea7e1c2c23840f74eb77280e79e9d6ff25fecd876f9b285c122709f0e9d10100e9b17f7035e
@@ -2,29 +2,31 @@ module React
2
2
  module Component
3
3
 
4
4
  module ClassMethods
5
-
5
+
6
6
  def url_param_evaluators
7
- @url_param_evaluators ||= {}
7
+ @url_param_evaluators ||= []
8
8
  end
9
-
9
+
10
10
  attr_accessor :evaluated_url_params
11
-
12
- def router_param(name, &block)
13
-
14
- url_param_evaluators[name] = block
15
-
11
+
12
+ def router_param(name, opts = {}, &block)
13
+
14
+ method_name = opts[:as] || name
15
+
16
+ url_param_evaluators << [name, block]
17
+
16
18
  class << self
17
- define_method name do
19
+ define_method method_name do
18
20
  evaluated_url_params[name]
19
21
  end
20
22
  end
21
-
22
- define_method name do
23
- self.class.send(name)
23
+
24
+ define_method method_name do
25
+ self.class.send(method_name)
24
26
  end
25
-
27
+
26
28
  end
27
-
29
+
28
30
  end
29
31
 
30
32
  def route_handler(*args)
@@ -35,6 +37,6 @@ module React
35
37
  opts[:params] = opts[:params].to_n if opts[:params]
36
38
  Router::RR::Link(opts, &block)
37
39
  end
38
-
40
+
39
41
  end
40
42
  end
@@ -19,18 +19,19 @@ module React
19
19
  native_mixin `ReactRouter.Navigation`
20
20
  native_mixin `ReactRouter.State`
21
21
 
22
- def get_path
23
- path = `self.native.getPath()`
22
+ def self.get_path
23
+ path = `#{@router_component}.native.getPath()`
24
24
  path = nil if `typeof path === 'undefined'`
25
25
  path
26
26
  end
27
27
 
28
- def replace_with(route_or_path, params = nil, query = nil)
29
- `self.native.replaceWith.apply(self.native, #{[route_or_path, params].compact})`
28
+ def self.replace_with(route_or_path, params = nil, query = nil)
29
+ `#{@router_component}.native.replaceWith.apply(self.native, #{[route_or_path, params, query].compact})`
30
30
  end
31
31
 
32
- def transition_to(route_or_path, params = nil, query = nil)
33
- `self.native.transitionTo.apply(self.native, #{[route_or_path, params].compact})`
32
+ def self.transition_to(route_or_path, params = @router_component.params[:router_state][:params], query = @router_component.params[:router_state][:query])
33
+ params = [route_or_path, params.to_n, query.to_n].compact
34
+ `#{@router_component}.native.transitionTo.apply(self.native, #{params})`
34
35
  end
35
36
 
36
37
  static_call_back "willTransitionTo" do |transition, params, query, callback|
@@ -39,9 +40,11 @@ module React
39
40
  transition = `transition.path`
40
41
  puts "willTransitionTo(#{transition}, #{params}, #{query})"
41
42
  begin
42
- params.each do |param, value|
43
- if evaluator = url_param_evaluators[param]
44
- evaluated_url_params[param] = evaluator.call(value)
43
+ url_param_evaluators.each do |name, block|
44
+ begin
45
+ evaluated_url_params[name] = block.call(params[name]) if params.has_key? name
46
+ rescue Exception => e
47
+ log("failed to process router param #{name} (#{params[name]}): #{e}", :error)
45
48
  end
46
49
  end
47
50
  if self.respond_to? :will_transition_to
@@ -121,7 +124,7 @@ module React
121
124
  end
122
125
 
123
126
  after_mount do
124
- unless self.class.routing!
127
+ if !self.class.routing!
125
128
  dom_node = if `typeof React.findDOMNode === 'undefined'`
126
129
  `#{self}.native.getDOMNode` # v0.12.0
127
130
  else
@@ -134,6 +137,8 @@ module React
134
137
  React.render(React.createElement(root, self.native.props), #{dom_node});
135
138
  });
136
139
  }
140
+ elsif respond_to? :show
141
+ self.class.instance_variable_set(:@router_component, self)
137
142
  end
138
143
  end
139
144
 
@@ -158,6 +163,8 @@ module React
158
163
  opts = opts.dup
159
164
  opts[:handler] = React::API.create_native_react_class(opts[:handler])
160
165
  (generate_node ? RR::Route_as_node(opts, &block) : RR::Route(opts, &block))
166
+ rescue Exception => e
167
+ React::IsomorphicHelpers.log("Could not define route #{opts}: #{e}", :error)
161
168
  end
162
169
 
163
170
  def self.default_route(ops = {}, &block)
@@ -1,3 +1,3 @@
1
1
  module ReactiveRouter
2
- VERSION = "0.7.4"
2
+ VERSION = "0.7.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reactive-router
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.4
4
+ version: 0.7.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam George
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-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler