From 87681ef39b6472f5c5dace58d1dab6c83fbc909b Mon Sep 17 00:00:00 2001 From: "mr. keith" Date: Mon, 26 Jan 2015 01:20:38 -0800 Subject: [PATCH] refactor: readying for 1.0 release Former-commit-id: a8841e89b8872e19fad334be51bf7276d8a1b064 [formerly a158f7b054e4a20801ee2732c25f8ded48346858] Former-commit-id: cfe08562a4528c83417d3f681c47d8b790974dbf --- client/layout.ls | 87 ++++++++++++++++++++++++------------------------ 1 file changed, 43 insertions(+), 44 deletions(-) diff --git a/client/layout.ls b/client/layout.ls index d2746c60..dbcaddfa 100644 --- a/client/layout.ls +++ b/client/layout.ls @@ -24,51 +24,50 @@ window.notify = (title, obj={body:''}) -> # to better use desktop notifications # main -# --------- +# ---- # b00t react! -init-react! # expose app cursor - -# configure primus -primus = window.primus = Primus.connect! - ..on \close -> - # count seconds disconnected - if locals.env is \production - window.closed-duration = 0 - window.closed-duration-i = set-interval (-> window.closed-duration++), 1000ms - - ..on \changeset (c) -> - # alert on newer application version launch - if locals.env is \production - if c isnt locals.changeset - notify 'Reload' {body:'A newer version has launched!'} - - ..on \open -> - # alert user of a stale page? - if locals.env is \production and window.closed-duration-i - clear-interval that - if window.closed-duration > 3s - notify 'Reload' {body:'A newer version of this page is ready!'} - - window.spark-id <- primus.id # easy identify primus connection - - -# stream session updates from server -session = primus.channel \session - ..on \data (data) -> - cur = if typeof! data is \Object then data else JSON.parse data # force Object - if cur then app.update \session, -> Immutable.fromJS cur - ..on \open -> - window.sync-session = (key, value) -> - app = window.app - cur = if typeof! key is \Object # merge key as obj - app.merge-deep key - else - app.update-in [\session, key], -> value - owned = cur.update-in [\session, \spark-id], -> window.spark-id # add update's owner - session.write (owned.get \session .toJS!) - ..on \close -> # cleanup - delete window.sync-session - +init-react! # expose app cursor +init-primus! # setup realtime + + +function init-primus + primus = window.primus = Primus.connect! + ..on \close -> + # count seconds disconnected + if locals.env is \production + window.closed-duration = 0 + window.closed-duration-i = set-interval (-> window.closed-duration++), 1000ms + + ..on \changeset (c) -> + # alert on newer application version launch + if locals.env is \production + if c isnt locals.changeset + notify 'Reload' {body:'A newer version has launched!'} + + ..on \open -> + # alert user of a stale page? + if locals.env is \production and window.closed-duration-i + clear-interval that + if window.closed-duration > 3s + notify 'Reload' {body:'A newer version of this page is ready!'} + window.spark-id <- primus.id # easy identify primus connection + + # stream session updates from server + session = primus.channel \session + ..on \data (data) -> + cur = if typeof! data is \Object then data else JSON.parse data # force Object + if cur then app.update \session, -> Immutable.fromJS cur + ..on \open -> + window.sync-session = (key, value) -> + app = window.app + cur = if typeof! key is \Object # merge key as obj + app.merge-deep key + else + app.update-in [\session, key], -> value + owned = cur.update-in [\session, \spark-id], -> window.spark-id # add update's owner + session.write (owned.get \session .toJS!) + ..on \close -> # cleanup + delete window.sync-session function init-react [locals, path] = [window.locals, window.location.pathname]