Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
63 lines (50 sloc) 1.43 KB
memoryStore = {}
ids = 1
module.exports = (req, res, ss) ->
# Preload session data in to req.session
create: (model) ->
cid = req.cid = ids++
res =
cid: cid
model: model
method: "confirm"
modelname: "Todo"
memoryStore[] = model
ss.publish.socketId req.socketId, "sync:Todo:" + cid, JSON.stringify(res)
delete res.cid
res.method = "create"
ss.publish.all "sync:Todo", JSON.stringify(res)
update: (model) ->
memoryStore[] and (memoryStore[] = model)
res =
model: model
method: "update"
modelname: "Todo"
res = JSON.stringify(res)
ss.publish.all "sync:Todo:" +, res
read: (model) ->
fetchedModel = memoryStore[]
res =
model: fetchedModel
method: "read"
modelname: "Todo"
ss.publish.socketId req.socketId, "sync:Todo:" +, JSON.stringify(res)
# For collections requesting all models at once
readAll: (model) ->
models = []
for id of memoryStore
models.push memoryStore[id]
res =
models: models
method: "read"
modelname: "Todo"
ss.publish.socketId req.socketId, "sync:Todo", JSON.stringify(res)
delete: (model) ->
if delete memoryStore[]
res =
method: "delete"
model: model
modelname: "Todo"
ss.publish.all "sync:Todo:" +, JSON.stringify(res)
Jump to Line
Something went wrong with that request. Please try again.