Class: React::Router
- Inherits:
-
Object
- Object
- React::Router
- Includes:
- Component
- 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
Defined Under Namespace
Class Method Summary collapse
Instance Method Summary collapse
- #browser_history ⇒ Object
- #build_routes(&block) ⇒ Object
- #create_element_wrapper ⇒ Object
- #gather_params ⇒ Object
- #hash_history ⇒ 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
.Link(to, opts = {}, &children) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/react/router.rb', line 5 def self.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
#browser_history ⇒ Object
39 40 41 |
# File 'lib/react/router.rb', line 39 def browser_history `window.ReactRouter.browserHistory` end |
#build_routes(&block) ⇒ Object
31 32 33 |
# File 'lib/react/router.rb', line 31 def build_routes(&block) React::Router::DSL.build_routes(&block) end |
#create_element_wrapper ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/react/router.rb', line 74 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
43 44 45 46 47 48 49 50 |
# File 'lib/react/router.rb', line 43 def gather_params params = { routes: React::Router::DSL.children_to_n(build_routes { routes }) } params[:history] = history 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 |
#hash_history ⇒ Object
35 36 37 |
# File 'lib/react/router.rb', line 35 def hash_history `window.ReactRouter.hashHistory` end |
#index(opts = {}) ⇒ Object
19 20 21 |
# File 'lib/react/router.rb', line 19 def index(opts = {}) DSL::Index.new(opts) end |
#index_redirect(opts = {}) ⇒ Object
27 28 29 |
# File 'lib/react/router.rb', line 27 def index_redirect(opts = {}) DSL::Index.new(opts).on(:enter) { |c| c.replace(opts[:to]) } end |
#on_error_wrapper ⇒ Object
90 91 92 |
# File 'lib/react/router.rb', line 90 def on_error_wrapper -> () { on_error() } end |
#on_update_wrapper ⇒ Object
70 71 72 |
# File 'lib/react/router.rb', line 70 def on_update_wrapper -> { on_update(Hash.new(`this.props`), Hash.new(`this.state`)) } end |
#parse_query_string_wrapper ⇒ Object
66 67 68 |
# File 'lib/react/router.rb', line 66 def parse_query_string_wrapper ->(query_string) { parse_query_string(query_string) } end |
#redirect(from, opts = {}) ⇒ Object
23 24 25 |
# File 'lib/react/router.rb', line 23 def redirect(from, opts = {}) DSL::Route.new(opts.merge(path: from)).on(:enter) { |c| c.replace(opts[:to]) } end |
#render ⇒ Object
52 53 54 |
# File 'lib/react/router.rb', line 52 def render Native::Router(gather_params) end |
#route(*args, &children) ⇒ Object
15 16 17 |
# File 'lib/react/router.rb', line 15 def route(*args, &children) DSL::Route.new(*args, &children) end |
#stringify_query_wrapper ⇒ Object
62 63 64 |
# File 'lib/react/router.rb', line 62 def stringify_query_wrapper ->(query) { stringify_query(query) } end |