Mercurial > code > home > repos > light9
changeset 1357:49f80544a3fb
untested unsubscribe handle support
Ignore-this: dab69fabac0055146be720ac474b615f
author | Drew Perttula <drewp@bigasterisk.com> |
---|---|
date | Sun, 05 Jun 2016 09:20:02 +0000 |
parents | 16aa26b7d685 |
children | 6ea2e1aa5070 |
files | light9/web/graph.coffee |
diffstat | 1 files changed, 9 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/light9/web/graph.coffee Sun Jun 05 06:23:01 2016 +0000 +++ b/light9/web/graph.coffee Sun Jun 05 09:20:02 2016 +0000 @@ -17,9 +17,15 @@ if not @handlersSp[s][p] @handlersSp[s][p] = [] @handlersSp[s][p].push(onChange) + handle = {s: s, p: p, func: onChange} + return handle unsubscribe: (subscription) -> - throw Error('not implemented') + spList = @handlersSp[subscription.s][subscription.p] + i = spList.indexOf(subscription.func) + if i == -1 + throw new Error('subscription not found') + spList.splice(i, 1) matchingHandlers: (quad) -> matches = [] @@ -267,10 +273,11 @@ # onChange is called with a patch that's limited to the quads # that match your request. # We call you immediately on existing triples. - @_watchers.subscribe(s, p, o, onChange) + handle = @_watchers.subscribe(s, p, o, onChange) immediatePatch = {delQuads: [], addQuads: @graph.findByIRI(s, p, o)} if immediatePatch.addQuads.length onChange(immediatePatch) + return handle unsubscribe: (subscription) -> @_watchers.unsubscribe(subscription)