Class: React::Router
- Inherits:
-
Object
- Object
- React::Router
- Includes:
- Hyperloop::Component::Mixin
- Defined in:
- lib/react/router.rb,
lib/react/router/dsl.rb,
lib/react/router/dsl/index.rb,
lib/react/router/dsl/route.rb,
lib/react/router/dsl/route/hooks.rb,
lib/react/router/dsl/route/wrappers.rb,
lib/react/router/dsl/transition_context.rb
Direct Known Subclasses
Defined Under Namespace
Class Method Summary collapse
- .browser_history ⇒ Object
- .create_memory_history(opts = {}) ⇒ Object
- .hash_history ⇒ Object
- .Link(to, opts = {}, &children) ⇒ Object
Instance Method Summary collapse
- #build_routes(&block) ⇒ Object
- #create_element_wrapper ⇒ Object
- #gather_params ⇒ Object
- #index(opts = {}) ⇒ Object
- #index_redirect(opts = {}) ⇒ Object
- #on_error_wrapper ⇒ Object
- #on_update_wrapper ⇒ Object
- #parse_query_string_wrapper ⇒ Object
- #redirect(from, opts = {}) ⇒ Object
- #render ⇒ Object
- #route(*args, &children) ⇒ Object
- #stringify_query_wrapper ⇒ Object
Class Method Details
.browser_history ⇒ Object
10 11 12 |
# File 'lib/react/router.rb', line 10 def browser_history RouterHistory.new(`ReactRouter.browserHistory`) end |
.create_memory_history(opts = {}) ⇒ Object
14 15 16 |
# File 'lib/react/router.rb', line 14 def create_memory_history(opts = {}) RouterHistory.new(`ReactRouter.createMemoryHistory(#{opts.to_n})`) end |
.hash_history ⇒ Object
6 7 8 |
# File 'lib/react/router.rb', line 6 def hash_history RouterHistory.new(`ReactRouter.hashHistory`) end |
.Link(to, opts = {}, &children) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/react/router.rb', line 18 def Link(to, opts = {}, &children) opts[:activeClassName] = opts.delete(:active_class).to_n if opts[:active_class] opts[:activeStyle] = opts.delete(:active_style).to_n if opts[:active_style] if opts[:only_active_on_index] opts[:onlyActiveOnIndex] = opts.delete(:only_active_on_index).to_n end opts[:to] = to.to_n Native::Link(opts, &children) end |
Instance Method Details
#build_routes(&block) ⇒ Object
45 46 47 |
# File 'lib/react/router.rb', line 45 def build_routes(&block) React::Router::DSL.build_routes(&block) end |
#create_element_wrapper ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/react/router.rb', line 80 def create_element_wrapper lambda do |component, props| comp_classes = React::API.class_eval { @@component_classes } rb_component = comp_classes.detect { |_key, value| value == component }.first # Not sure if this could ever happen, # could not figure out a way to test it so commented it out. # unless rb_component # rb_component = Class.new(React::Component::Base) # comp_classes[rb_component] = component # end rb_props = convert_props(props) result = create_element(rb_component, rb_props) convert_or_create_element(result, component, props, rb_component, rb_props) end end |
#gather_params ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/react/router.rb', line 49 def gather_params params = { routes: React::Router::DSL.children_to_n(build_routes { routes }) } params[:history] = history.to_n if respond_to? :history %w(create_element stringify_query parse_query_string on_error on_update).each do |method| params[method.camelcase(false)] = send("#{method}_wrapper") if respond_to? method end params end |
#index(opts = {}) ⇒ Object
33 34 35 |
# File 'lib/react/router.rb', line 33 def index(opts = {}) DSL::Index.new(opts) end |
#index_redirect(opts = {}) ⇒ Object
41 42 43 |
# File 'lib/react/router.rb', line 41 def index_redirect(opts = {}) DSL::Index.new(opts).on(:enter) { |c| c.replace(opts[:to]) } end |
#on_error_wrapper ⇒ Object
96 97 98 |
# File 'lib/react/router.rb', line 96 def on_error_wrapper -> () { on_error() } end |
#on_update_wrapper ⇒ Object
76 77 78 |
# File 'lib/react/router.rb', line 76 def on_update_wrapper -> { on_update(Hash.new(`this.props`), Hash.new(`this.state`)) } end |
#parse_query_string_wrapper ⇒ Object
72 73 74 |
# File 'lib/react/router.rb', line 72 def parse_query_string_wrapper ->(query_string) { parse_query_string(query_string) } end |
#redirect(from, opts = {}) ⇒ Object
37 38 39 |
# File 'lib/react/router.rb', line 37 def redirect(from, opts = {}) DSL::Route.new(opts.merge(path: from)).on(:enter) { |c| c.replace(opts[:to]) } end |
#render ⇒ Object
58 59 60 |
# File 'lib/react/router.rb', line 58 def render Native::Router(gather_params) end |
#route(*args, &children) ⇒ Object
29 30 31 |
# File 'lib/react/router.rb', line 29 def route(*args, &children) DSL::Route.new(*args, &children) end |
#stringify_query_wrapper ⇒ Object
68 69 70 |
# File 'lib/react/router.rb', line 68 def stringify_query_wrapper ->(query) { stringify_query(query) } end |