Skip to content

Commit

Permalink
Parse params only on change
Browse files Browse the repository at this point in the history
  • Loading branch information
fazibear committed Sep 27, 2016
1 parent 4dfd8c2 commit dd2f6e6
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions opal/inesita/router.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ def initialize
raise Error, 'Add #routes method to router!' unless respond_to?(:routes)
routes
raise Error, 'Add #route to your #routes method!' if @routes.routes.empty?
find_route
parse_url_params
add_listeners
end

def add_listeners
Browser.onpopstate { render! }
Browser.hashchange { render! }
Browser.onpopstate { parse_url_params; render! }
Browser.hashchange { parse_url_params; render! }
end

def route(*params, &block)
Expand All @@ -40,18 +42,18 @@ def find_route
end

def find_component(route)
find_route
@component_props = route[:component_props]
route[:component]
end

def render
find_route
parse_url_params
component find_component(@route), props: @component_props if @route
end

def go_to(p)
Browser.push_state(p)
parse_url_params
render!
false
end
Expand Down

0 comments on commit dd2f6e6

Please sign in to comment.