FDC3 / API

Open standards for the financial desktop.
https://fdc3.finos.org
Apache License 2.0
9 stars 9 forks source link

listener objects don't have a mechanism for unsubscribing #5

Closed ColinEberhardt closed 6 years ago

ColinEberhardt commented 6 years ago

Both the IntentListener and ContextListener allow you to subscribe to events raised by the Desktop Agent. However, neither of them have a mechanism for removing this subscription.

Also, their relationships with the Desktop Agent is a little hidden, I'm guessing that they access some global agent instance in order to register themselves? This has a couple of issues:

  1. It relies on a singleton Desktop Agent
  2. The relationship between agent / listener isn't explicit - which can give rise to memory leaks.

I'd prefer to see a more explicit subscribe / unsubscribe:

For example:

const viewChartListener = fdc3.addIntentListener("ViewChart", (context) => {
  // do something meaningful here ...
  console.log("intent event occurred with context", context);
});

// .. at some point in the future ..
viewChartListener.unsubscribe();
nkolba commented 6 years ago

Agreed.

nkolba commented 6 years ago

Added unsubscribe methods for Context and Intent listeners