Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
Former-commit-id: 3aa876f
Former-commit-id: ddb8e3e
  • Loading branch information
khoerling committed Jan 26, 2015
2 parents 4e1926b + 87681ef commit 7e7e3d1
Showing 1 changed file with 43 additions and 44 deletions.
87 changes: 43 additions & 44 deletions client/layout.ls
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 7e7e3d1

Please sign in to comment.