Skip to content

Commit

Permalink
fix(cozy-realtime): Don't crash if no event exist
Browse files Browse the repository at this point in the history
Doing `Object.keys(this._events)` thrown an error when `this._events`
was undefined. We already had a `_getEventKeys` method that handles
this. So I just used it.
  • Loading branch information
Cyrille Perois authored and drazik committed Jan 3, 2020
1 parent 051486d commit 654c3ed
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/cozy-realtime/src/CozyRealtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ class CozyRealtime {
*/
_retryLimit = 60

/**
* Mapping between events and associated callbacks
*
* @type {Object}
*/
_events = {}

/**
* Constructor of CozyRealtime:
* - Save cozyClient
Expand Down Expand Up @@ -206,9 +213,8 @@ class CozyRealtime {
_resubscribe() {
this._retryLimit--

const subscribeList = Object.keys(this._events)
const subscribeList = this._getEventKeys(this._events)
.map(key => {
if (!key.includes(INDEX_KEY_SEPARATOR)) return
if (this._events[key].length === 0) return
let [, type, id] = key.split(INDEX_KEY_SEPARATOR)
if (id === 'undefined') id = undefined
Expand Down

0 comments on commit 654c3ed

Please sign in to comment.