From a2e8c09775256a2b6188ecb00b8d9c44151a35a3 Mon Sep 17 00:00:00 2001 From: Daniel Compton Date: Sun, 27 Sep 2015 21:39:35 +1300 Subject: [PATCH] Use yield instead of (timeout 0) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (timeout 0) resolves to using js/setTimeout which will actually take 4+ msecs in browsers. This is an eternity. The nextTick approach was proposed by Patrick O'Brien and implemented here. Docs on nextTick from Closure library: Fires the provided callbacks as soon as possible after the current JS execution context. setTimeout(…, 0) takes at least 4ms when called from within another setTimeout(…, 0) for legacy reasons. This will not schedule the callback as a microtask (i.e. a task that can preempt user input or networking callbacks). It is meant to emulate what setTimeout(_, 0) would do if it were not throttled. If you desire microtask behavior, use goog.Promise instead. --- src/re_frame/router.cljs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/re_frame/router.cljs b/src/re_frame/router.cljs index b4f6186..0ebb35d 100644 --- a/src/re_frame/router.cljs +++ b/src/re_frame/router.cljs @@ -4,7 +4,8 @@ (:require [reagent.core :refer [flush]] [re-frame.handlers :refer [handle]] [re-frame.utils :refer [warn error]] - [cljs.core.async :refer [chan put!