Module: HyperRouter::ClassMethods
- Defined in:
- lib/hyper-router/class_methods.rb
Instance Method Summary collapse
- #browser_history ⇒ Object
- #hash_history(*args) ⇒ Object
- #history(history_type) ⇒ Object
- #memory_history(*args) ⇒ Object
- #prerender_path(*args) ⇒ Object
- #prerender_router(&block) ⇒ Object
- #route(&block) ⇒ Object
Instance Method Details
#browser_history ⇒ Object
41 42 43 |
# File 'lib/hyper-router/class_methods.rb', line 41 def browser_history React::Router::History.current.create_browser_history end |
#hash_history(*args) ⇒ Object
45 46 47 |
# File 'lib/hyper-router/class_methods.rb', line 45 def hash_history(*args) React::Router::History.current.create_hash_history(*args) end |
#history(history_type) ⇒ Object
13 14 15 16 17 |
# File 'lib/hyper-router/class_methods.rb', line 13 def history(history_type) define_method(:history) do @history ||= self.class.send(:"#{history_type}_history") end end |
#memory_history(*args) ⇒ Object
49 50 51 |
# File 'lib/hyper-router/class_methods.rb', line 49 def memory_history(*args) React::Router::History.current.create_memory_history(*args) end |
#prerender_path(*args) ⇒ Object
3 4 5 6 7 8 9 10 11 |
# File 'lib/hyper-router/class_methods.rb', line 3 def prerender_path(*args) name = args[0].is_a?(Hash) ? args[0].first[0] : args[0] define_method(:prerender_path) do params.send(:"#{name}") end param(*args) end |
#prerender_router(&block) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/hyper-router/class_methods.rb', line 19 def prerender_router(&block) define_method(:render) do location = {}.tap do |hash| pathname, search = (respond_to?(:prerender_path) ? prerender_path : '').split('?', 2) hash[:pathname] = pathname hash[:search] = search ? "?#{search}" : '' end React::Router::StaticRouter(location: location.to_n, context: {}.to_n) do instance_eval(&block) end end end |
#route(&block) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/hyper-router/class_methods.rb', line 33 def route(&block) if React::IsomorphicHelpers.on_opal_client? render_router(&block) else prerender_router(&block) end end |