subscribe and unsubscribe

This commit is contained in:
Philippe PITTOLI 2019-12-06 03:16:48 +01:00
parent 03e653acd3
commit bf1ba794bd
2 changed files with 28 additions and 10 deletions

View File

@ -222,6 +222,7 @@ render-navbar = ->
h \div.navbar-start [ h \div.navbar-start [
h \a.navbar-item.is-size-2 { h \a.navbar-item.is-size-2 {
onclick: -> onclick: ->
model.todod-ws.unsubscribe model.viewed-project.id
model.viewed-project := void model.viewed-project := void
model.current-view := "project-list" model.current-view := "project-list"
} [ "⌂" ] } [ "⌂" ]
@ -243,6 +244,7 @@ render-project-list = ->
onclick: -> onclick: ->
model.current-view := "project" model.current-view := "project"
model.viewed-project := project.id model.viewed-project := project.id
model.todod-ws.subscribe project.id
model.todod-ws.get-list project.id model.todod-ws.get-list project.id
model.todod-ws.get-tasks project.id model.todod-ws.get-tasks project.id
} [ } [

View File

@ -9,16 +9,18 @@ module.exports = {
self = {} self = {}
request-types = { request-types = {
"list-lists": 0 "list-lists": 0
"get-list": 1 "get-list": 1
"add-list": 2 "add-list": 2
"edit-list": 3 "edit-list": 3
"remove-list": 4 "remove-list": 4
"get-tasks": 5 "get-tasks": 5
"get-task": 6 "get-task": 6
"add-task": 7 "add-task": 7
"remove-task": 8 "remove-task": 8
"edit-task": 9 "edit-task": 9
"subscribe": 10
"unsubscribe": 11
} }
response-types = { response-types = {
@ -33,6 +35,8 @@ module.exports = {
"task-created": 8 "task-created": 8
"task-removed": 9 "task-removed": 9
"task-updated": 10 "task-updated": 10
"subscribed": 11
"unsubscribed": 12
} }
# users can record functions to run on events # users can record functions to run on events
@ -162,5 +166,17 @@ module.exports = {
self.send request-types[\edit-task], JSON.stringify payload self.send request-types[\edit-task], JSON.stringify payload
self.subscribe = (list-id) ->
self.send request-types[\subscribe], JSON.stringify {
token: self.token
list: list-id
}
self.unsubscribe = (list-id) ->
self.send request-types[\unsubscribe], JSON.stringify {
token: self.token
list: list-id
}
self self
} }