1

I have a model that will subscribe a websocket to several expensive end points when the user is on particular routes. When the user leaves the route, I want to disconnect the websockets.

The dva api docs say

Notice: if we want to unregister a model with app.unmodel(), it's subscriptions must return unsubscribe method.

However the docs do not include how to register a subscription with an unsubscribe method.

How does one create a subscription with an unsubscribe handler?

Community
  • 1
  • 1
megawac
  • 10,953
  • 5
  • 40
  • 61

1 Answers1

1

It's necessary to add return to the end of your function.

  subscriptions: {
    setup() {
      emitter.on('event', () => {
        emitterCount += 1;
      });

      return () => {
        emitter.removeAllListeners();
      };
    },
  },
Jonáš Krutil
  • 245
  • 1
  • 9