Skip to content

Commit

Permalink
fix(cozy-realtime): Imperfect fix for unsubscribe (#378)
Browse files Browse the repository at this point in the history
  • Loading branch information
Crash-- committed Apr 12, 2019
1 parent 5a03109 commit 8e9e9ab
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/cozy-realtime/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,18 @@ export function subscribe(config, doctype, { docId, parse = doc => doc } = {}) {
const subscription = {
onUpdate: listener => {
updateListener = parseCurried(listener)
cozySocket.subscribe(doctype, 'updated', updateListener, docId)
cozySocket &&
cozySocket.subscribe(doctype, 'updated', updateListener, docId)
return subscription
},
onDelete: listener => {
deleteListener = parseCurried(listener)
cozySocket.subscribe(doctype, 'deleted', deleteListener, docId)
cozySocket &&
cozySocket.subscribe(doctype, 'deleted', deleteListener, docId)
return subscription
},
unsubscribe: () => {
if (!cozySocket) return
if (subscribeAllDocs) {
cozySocket.unsubscribe(doctype, 'created', createListener)
}
Expand All @@ -323,7 +326,7 @@ export function subscribe(config, doctype, { docId, parse = doc => doc } = {}) {
if (subscribeAllDocs) {
subscription.onCreate = listener => {
createListener = parseCurried(listener)
cozySocket.subscribe(doctype, 'created', createListener)
cozySocket && cozySocket.subscribe(doctype, 'created', createListener)
return subscription
}
}
Expand Down

0 comments on commit 8e9e9ab

Please sign in to comment.