ev.off() seems to kill listeners when switching be

2019-08-07 01:12发布

I have list with a filter that toggles between "all" and "favorites". This works OK. However, when I activate the outcommented ev.off() in both methods, a toggle from one filter to the other will not produce results anymore. Both lists will stay empty from that point on. (btw: since ev.off() is still experimental, I'm ok for now, not using it. Maybe this info might help for future release)

1.subscribe() method that calls the relevant list methods

export const subscribe          = (payload, cb) => {
const filter = payload.filter
const user   = payload.user
switch (filter) {
  case 'all' :
    subscribeAllSkills(cb)
    break
  case 'favorites' :
    subscribeFavoriteSkills(user, cb)
    break
    ...
  }
}

2.subscribeAllSkills()

const subscribeAllSkills        = (cb) => {
  gun.get('skill')
     .map()
     .on(
       (skill, pk, ctx, ev) => {
           //ev.off()
           cb(skill, pk)
       }
     )
}

3.

const subscribeFavoriteSkills   = (user, cb) => {
  gun.get('user')
   .get(user.pk)
   .get('favorite_skill')
   .map()
   .on(
     (skill, pk, ctx, ev) => {
       //ev.off()
       cb(skill, pk)
     }
   )
}

标签: gun
0条回答
登录 后发表回答