hyper-router 1.0.alpha1.2 → 1.0.alpha1.3

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
  SHA256:
3
- metadata.gz: b2076235a7851fea3270717dc0104f839a004751f65f4bd4ce73ac08682bead6
4
- data.tar.gz: 61d62fe953ff92b070fd70d4b5ed3c70b540ff8adb57026428537030e9e31f1d
3
+ metadata.gz: 0515b59167c89bfa088fb19da74c6006abceadddf1ee2dcbc0b7c38cfd382142
4
+ data.tar.gz: d753ef19d61e22c45fc39f2dc513e855cce7a80b4d305321b68ad60e00b0ece9
5
5
  SHA512:
6
- metadata.gz: 97e2efa72feb813e8fa7be7ad4d14f594b3be21d95cbacb6edc0eb45b4e83c9309d909d250a63a17a10d38ffe2f9324f743114e46b9956214de7961ada37c306
7
- data.tar.gz: 2c9279c27f330d796d772d2092f0e8db8934704e9efb949cefa6b433c59b6e3b2401d6b7ff498e73373aaeddf30e9428159fdbb840a6cc2e37ceeb4f803ec1a2
6
+ metadata.gz: e317f71356ac069cd2915eab6877d52fd552e5aa4da8f502e7e45f4d7ca95a761892e1aa0e00e49948e57ee930f9b0910003702d223ef703b8a78cb9fbe7e4e6
7
+ data.tar.gz: a033f24ad047ef0d66e6b43e2bc9d6b7414605bec760cb1cb9a294131efe588625c9eaf52bcaa91366ee3536b6e27404fab161ff116d050c6a6549b53268d5b4
@@ -14,29 +14,6 @@ module Hyperstack
14
14
  Hyperstack::Router::Location.new(`#{history.to_n}.location`)
15
15
  end
16
16
 
17
- def render(container = nil, params = {}, &block)
18
- if container
19
- container = container.type if container.is_a? Hyperstack::Component::Element
20
- select_router do
21
- Hyperstack::Internal::Component::RenderingContext.render(container, params) do
22
- instance_eval(&block) if block
23
- end
24
- end
25
- else
26
- select_router { instance_eval(&block) }
27
- end
28
- end
29
-
30
- def select_router(&block)
31
- if Hyperstack::Component::IsomorphicHelpers.on_opal_server?
32
- prerender_router(&block)
33
- else
34
- render_router(&block)
35
- end
36
- end
37
-
38
- alias route render
39
-
40
17
  private
41
18
 
42
19
  def browser_history
@@ -50,30 +27,6 @@ module Hyperstack
50
27
  def memory_history(*args)
51
28
  @__memory_history ||= React::Router::History.current.create_memory_history(*args)
52
29
  end
53
-
54
- def render_router(&block)
55
- define_method(:__hyperstack_component_render) do
56
- self.class.history :browser unless history
57
-
58
- React::Router::Router(history: history.to_n) do
59
- instance_eval(&block)
60
- end
61
- end
62
- end
63
-
64
- def prerender_router(&block)
65
- define_method(:__hyperstack_component_render) do
66
- location = {}.tap do |hash|
67
- pathname, search = IsomorphicMethods.request_fullpath.split('?', 2)
68
- hash[:pathname] = pathname
69
- hash[:search] = search ? "?#{search}" : ''
70
- end
71
-
72
- React::Router::StaticRouter(location: location.to_n, context: {}.to_n) do
73
- instance_eval(&block)
74
- end
75
- end
76
- end
77
30
  end
78
31
  end
79
32
  end
@@ -25,6 +25,9 @@ module Hyperstack
25
25
 
26
26
  def Redirect(to, opts = {})
27
27
  opts[:to] = to.to_n
28
+ status = opts.delete(:status)
29
+ status ||= 302
30
+ `#{IsomorphicMethods.ctx}.status = #{status}`
28
31
  React::Router::Redirect(opts)
29
32
  end
30
33
 
@@ -37,6 +40,8 @@ module Hyperstack
37
40
  end
38
41
 
39
42
  def Route(to, opts = {}, &block)
43
+ Hyperstack::Internal::State::Mapper.observed! Hyperstack::Router::Location
44
+
40
45
  opts[:path] = to.to_n
41
46
 
42
47
  if opts[:mounts]
@@ -53,7 +58,7 @@ module Hyperstack
53
58
  opts[:render] = lambda do |e|
54
59
  route_params = format_params(e)
55
60
 
56
- yield(route_params.values).to_n
61
+ yield(*route_params.values).to_n
57
62
  end
58
63
  end
59
64
 
@@ -4,6 +4,17 @@ module Hyperstack
4
4
  class IsomorphicMethods
5
5
  include Hyperstack::Component::IsomorphicHelpers
6
6
 
7
+ def self.ctx
8
+ @ctx ||= `{}`
9
+ end
10
+
11
+ prerender_footer do |_controller|
12
+ next unless on_opal_server?
13
+ ctx_as_hash = Hash.new(@ctx)
14
+ @ctx = `{}`
15
+ raise "Hyperstack::Internal::Component::Redirect #{ctx_as_hash[:url]} status: #{ctx_as_hash[:status]}" if ctx_as_hash[:url]
16
+ end
17
+
7
18
  isomorphic_method(:request_fullpath) do |f|
8
19
  f.when_on_client { `window.location.pathname` }
9
20
  f.send_to_server
@@ -1,6 +1,50 @@
1
1
  module Hyperstack
2
2
  module Router
3
3
  class NoHistoryError < StandardError; end
4
+
5
+ def __hyperstack_router_wrapper(&block)
6
+ if Hyperstack::Component::IsomorphicHelpers.on_opal_server?
7
+ ->() { __hyperstack_prerender_router(&block) }
8
+ else
9
+ ->() { __hyperstack_render_router(&block) }
10
+ end
11
+ end
12
+
13
+ def __eval_block(block)
14
+ result = instance_eval(&block)
15
+ if result.is_a?(String) ||
16
+ (result.respond_to?(:acts_as_string?) && result.acts_as_string?)
17
+ # hyper-mesh DummyValues respond to acts_as_string, and must
18
+ # be converted to spans INSIDE the parent, otherwise the waiting_on_resources
19
+ # flag will get set in the wrong context
20
+ result = Hyperstack::Internal::Component::RenderingContext
21
+ .render(:span) { result.to_s }
22
+ end
23
+ result
24
+ end
25
+
26
+ def __hyperstack_render_router(&block)
27
+ instance_eval do
28
+ self.class.history :browser unless history
29
+ React::Router::Router(history: history.to_n) do
30
+ __eval_block(block)
31
+ end
32
+ end
33
+ end
34
+
35
+ def __hyperstack_prerender_router(&block)
36
+ instance_eval do
37
+ pathname, search = Hyperstack::Internal::Router::IsomorphicMethods.request_fullpath.split('?', 2)
38
+ location = { pathname: pathname, search: search ? "?#{search}" : '' }.to_n
39
+ React::Router::StaticRouter(
40
+ location: location,
41
+ context: Hyperstack::Internal::Router::IsomorphicMethods.ctx
42
+ ) do
43
+ __eval_block(block)
44
+ end
45
+ end
46
+ end
47
+
4
48
  def self.included(base)
5
49
  base.extend(Hyperstack::Internal::Router::ClassMethods)
6
50
 
@@ -1,3 +1,3 @@
1
1
  module HyperRouter
2
- VERSION = '1.0.alpha1.2'
2
+ VERSION = '1.0.alpha1.3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hyper-router
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.alpha1.2
4
+ version: 1.0.alpha1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam George
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-11-16 00:00:00.000000000 Z
12
+ date: 2019-01-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hyper-component
@@ -17,28 +17,28 @@ dependencies:
17
17
  requirements:
18
18
  - - '='
19
19
  - !ruby/object:Gem::Version
20
- version: 1.0.alpha1.2
20
+ version: 1.0.alpha1.3
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - '='
26
26
  - !ruby/object:Gem::Version
27
- version: 1.0.alpha1.2
27
+ version: 1.0.alpha1.3
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: hyper-state
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
32
  - - '='
33
33
  - !ruby/object:Gem::Version
34
- version: 1.0.alpha1.2
34
+ version: 1.0.alpha1.3
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - '='
40
40
  - !ruby/object:Gem::Version
41
- version: 1.0.alpha1.2
41
+ version: 1.0.alpha1.3
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: opal-browser
44
44
  requirement: !ruby/object:Gem::Requirement
@@ -59,14 +59,20 @@ dependencies:
59
59
  requirements:
60
60
  - - ">="
61
61
  - !ruby/object:Gem::Version
62
- version: '0'
62
+ version: 1.17.3
63
+ - - "<"
64
+ - !ruby/object:Gem::Version
65
+ version: '2.1'
63
66
  type: :development
64
67
  prerelease: false
65
68
  version_requirements: !ruby/object:Gem::Requirement
66
69
  requirements:
67
70
  - - ">="
68
71
  - !ruby/object:Gem::Version
69
- version: '0'
72
+ version: 1.17.3
73
+ - - "<"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.1'
70
76
  - !ruby/object:Gem::Dependency
71
77
  name: capybara
72
78
  requirement: !ruby/object:Gem::Requirement
@@ -115,28 +121,28 @@ dependencies:
115
121
  requirements:
116
122
  - - '='
117
123
  - !ruby/object:Gem::Version
118
- version: 1.0.alpha1.2
124
+ version: 1.0.alpha1.3
119
125
  type: :development
120
126
  prerelease: false
121
127
  version_requirements: !ruby/object:Gem::Requirement
122
128
  requirements:
123
129
  - - '='
124
130
  - !ruby/object:Gem::Version
125
- version: 1.0.alpha1.2
131
+ version: 1.0.alpha1.3
126
132
  - !ruby/object:Gem::Dependency
127
133
  name: hyper-store
128
134
  requirement: !ruby/object:Gem::Requirement
129
135
  requirements:
130
136
  - - '='
131
137
  - !ruby/object:Gem::Version
132
- version: 1.0.alpha1.2
138
+ version: 1.0.alpha1.3
133
139
  type: :development
134
140
  prerelease: false
135
141
  version_requirements: !ruby/object:Gem::Requirement
136
142
  requirements:
137
143
  - - '='
138
144
  - !ruby/object:Gem::Version
139
- version: 1.0.alpha1.2
145
+ version: 1.0.alpha1.3
140
146
  - !ruby/object:Gem::Dependency
141
147
  name: listen
142
148
  requirement: !ruby/object:Gem::Requirement
@@ -157,14 +163,14 @@ dependencies:
157
163
  requirements:
158
164
  - - "~>"
159
165
  - !ruby/object:Gem::Version
160
- version: 0.1.15
166
+ version: 0.2.4
161
167
  type: :development
162
168
  prerelease: false
163
169
  version_requirements: !ruby/object:Gem::Requirement
164
170
  requirements:
165
171
  - - "~>"
166
172
  - !ruby/object:Gem::Version
167
- version: 0.1.15
173
+ version: 0.2.4
168
174
  - !ruby/object:Gem::Dependency
169
175
  name: opal-rails
170
176
  requirement: !ruby/object:Gem::Requirement
@@ -491,8 +497,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
491
497
  - !ruby/object:Gem::Version
492
498
  version: 1.3.1
493
499
  requirements: []
494
- rubyforge_project:
495
- rubygems_version: 2.7.8
500
+ rubygems_version: 3.0.2
496
501
  signing_key:
497
502
  specification_version: 4
498
503
  summary: hyper-router for Opal, part of the hyperstack framework