From dd2f6e6a5ffc5fc56958c10923a1d45942c77180 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Kalbarczyk?= Date: Tue, 27 Sep 2016 18:06:09 +0200 Subject: [PATCH] Parse params only on change --- opal/inesita/router.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/opal/inesita/router.rb b/opal/inesita/router.rb index 9fec4cb..63c4637 100644 --- a/opal/inesita/router.rb +++ b/opal/inesita/router.rb @@ -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) @@ -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