reactive-router 0.7.5 → 0.7.6
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 +4 -4
- data/lib/reactive-router/component.rb +0 -22
- data/lib/reactive-router/router.rb +57 -19
- data/lib/reactive-router/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3dcdd11e337d8988b6bdd8a53a0574edb3112a6
|
4
|
+
data.tar.gz: 66d093331294658c98740d6993805646781e0149
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: abcef3451bacffb2a4e6eb352e3e96aadf956f5ad6c182b818fa4ab2c7adcf72a61678103bb6488f7793cc17a2ba72d3e4caf71e992ad60777ac45558bc77e4a
|
7
|
+
data.tar.gz: a415c2a9088e7f8054938831a27f06cc8685881fd0116d80f088dde560f3a5ba4e71c68c984ecb83619e4363c872c7526e438a3be560253038b8a85df390b5d6
|
@@ -3,29 +3,7 @@ module React
|
|
3
3
|
|
4
4
|
module ClassMethods
|
5
5
|
|
6
|
-
def url_param_evaluators
|
7
|
-
@url_param_evaluators ||= []
|
8
|
-
end
|
9
6
|
|
10
|
-
attr_accessor :evaluated_url_params
|
11
|
-
|
12
|
-
def router_param(name, opts = {}, &block)
|
13
|
-
|
14
|
-
method_name = opts[:as] || name
|
15
|
-
|
16
|
-
url_param_evaluators << [name, block]
|
17
|
-
|
18
|
-
class << self
|
19
|
-
define_method method_name do
|
20
|
-
evaluated_url_params[name]
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
define_method method_name do
|
25
|
-
self.class.send(method_name)
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
7
|
|
30
8
|
end
|
31
9
|
|
@@ -19,34 +19,68 @@ module React
|
|
19
19
|
native_mixin `ReactRouter.Navigation`
|
20
20
|
native_mixin `ReactRouter.State`
|
21
21
|
|
22
|
-
|
23
|
-
path = `#{@router_component}.native.getPath()`
|
24
|
-
path = nil if `typeof path === 'undefined'`
|
25
|
-
path
|
26
|
-
end
|
22
|
+
class << self
|
27
23
|
|
28
|
-
|
29
|
-
|
30
|
-
|
24
|
+
def get_path
|
25
|
+
path = `#{@router_component}.native.getPath()`
|
26
|
+
path = nil if `typeof path === 'undefined'`
|
27
|
+
path
|
28
|
+
end
|
31
29
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
end
|
30
|
+
def replace_with(route_or_path, params = nil, query = nil)
|
31
|
+
`#{@router_component}.native.replaceWith.apply(self.native, #{[route_or_path, params, query].compact})`
|
32
|
+
end
|
36
33
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
34
|
+
def transition_to(route_or_path, params = {}, query = {})
|
35
|
+
params = @router_component.params[:router_state][:params].merge params
|
36
|
+
query = @router_component.params[:router_state][:query].merge query
|
37
|
+
`#{@router_component}.native.transitionTo.apply(self.native, #{[route_or_path, params.to_n, query.to_n]})`
|
38
|
+
end
|
39
|
+
|
40
|
+
def url_param_evaluators
|
41
|
+
@url_param_evaluators ||= []
|
42
|
+
end
|
43
|
+
|
44
|
+
attr_accessor :evaluated_url_params
|
45
|
+
attr_accessor :current_url_params
|
46
|
+
|
47
|
+
def router_param(name, opts = {}, &block)
|
48
|
+
|
49
|
+
method_name = opts[:as] || name
|
50
|
+
|
51
|
+
url_param_evaluators << [name, block]
|
52
|
+
|
53
|
+
class << self
|
54
|
+
define_method method_name do
|
55
|
+
evaluated_url_params[name]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
define_method method_name do
|
60
|
+
self.class.send(method_name)
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
def evaluate_new_params(params)
|
43
66
|
url_param_evaluators.each do |name, block|
|
44
67
|
begin
|
45
|
-
evaluated_url_params[name] = block.call(params[name]) if params.has_key? name
|
68
|
+
evaluated_url_params[name] = block.call(params[name]) if params.has_key?(name) and current_url_params[name] != params[name]
|
69
|
+
current_url_params[name] = params[name]
|
46
70
|
rescue Exception => e
|
47
71
|
log("failed to process router param #{name} (#{params[name]}): #{e}", :error)
|
48
72
|
end
|
49
73
|
end
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
static_call_back "willTransitionTo" do |transition, params, query, callback|
|
79
|
+
params = Hash.new(params)
|
80
|
+
query = Hash.new(query)
|
81
|
+
transition = `transition.path`
|
82
|
+
puts "willTransitionTo(#{transition}, #{params}, #{query}) for router #{self.object_id}, router_component = #{@router_component.object_id}"
|
83
|
+
begin
|
50
84
|
if self.respond_to? :will_transition_to
|
51
85
|
result = will_transition_to transition, params, query if self.respond_to? :will_transition_to
|
52
86
|
if result.is_a? Promise
|
@@ -65,6 +99,7 @@ module React
|
|
65
99
|
before_first_mount do |context|
|
66
100
|
|
67
101
|
@evaluated_url_params = {}
|
102
|
+
@current_url_params = {}
|
68
103
|
if !self.instance_methods.include?(:show) # if there is no show method this is NOT a top level router so we assume routing will begin elsewhere
|
69
104
|
@routing = true
|
70
105
|
elsif `typeof ReactRouter === 'undefined'`
|
@@ -93,6 +128,7 @@ module React
|
|
93
128
|
|
94
129
|
def render
|
95
130
|
if self.class.routing?
|
131
|
+
self.class.evaluate_new_params url_params(params)
|
96
132
|
show
|
97
133
|
elsif on_opal_server?
|
98
134
|
self.class.routing!
|
@@ -125,6 +161,7 @@ module React
|
|
125
161
|
|
126
162
|
after_mount do
|
127
163
|
if !self.class.routing!
|
164
|
+
puts "after mount outside of ruby router #{self.object_id}, my class router is #{self.class.object_id}"
|
128
165
|
dom_node = if `typeof React.findDOMNode === 'undefined'`
|
129
166
|
`#{self}.native.getDOMNode` # v0.12.0
|
130
167
|
else
|
@@ -138,6 +175,7 @@ module React
|
|
138
175
|
});
|
139
176
|
}
|
140
177
|
elsif respond_to? :show
|
178
|
+
puts "after mount inside of ruby router #{self.object_id}, my class router is #{self.class.object_id}"
|
141
179
|
self.class.instance_variable_set(:@router_component, self)
|
142
180
|
end
|
143
181
|
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
|
+
version: 0.7.6
|
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-
|
11
|
+
date: 2015-09-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|