-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modifications to the Channels API + Window selectors. #121
Comments
Context filtering There's also an implicit assumption here that context filtering would only ever happen on the Window-level context listeners This is the main way channels are intended to be used - applications will typically only use the top-level |
I am highly supportive of adding context types to the broadcast listener, in fact I think I have suggested it more than once in the past. It also provides an opportunity for optimisation, as underlying messages can now be filtered down to only those ones applications are interested in. I personally prefer adding a single context type parameter, and using separate subscriptions if multiple types are required, as I think it makes for nicer consumption, but I am willing to be persuaded 😄 Also, 👍 on only supporting filtering by context type - it is the organising principle of FDC3, also for intents. I don't think adding context type filtering to broadcast implies it needs to be added to intents. Intents already support filtering context type in the app directory registration, and would just add unnecessary complexity for not a lot of gain. @chedzoir can you please add some before and after straw man code samples (of usage) to this issue? |
@pjbroadbent I'm not sure that you need to have the |
@chedzoir - My understanding is that most normal applications should be unaware of channels. The channels logic and switching to Thus expecting an app to remove the top level listener or not react to broadcast when it is in |
@vmehtafds - That's not at all what I mean. To clarify, I would expect that there is a method that the app has to know about that would allow it to subscribe to context and that's the limit of what the app needs to know about. In my original suggestion it could be Then the whole channel selectors are handled behind the scenes in that method. So if the window is set to Blue, the listener registered in All of this can be managed by global objects placed upon the window object by the container. |
@chedzoir @pjbroadbent @rikoe @vmehtafds Small topic: larger topic
|
In regard to the larger topic. I would upvote a filter for type(s).
Personally, I feel filtering on type is enough but wouldn't argue against a more generalized filtering template if others felt that was useful. We should certainly specify the signature in a way that doesn't preclude adding more complex filtering down the road. |
@thorsent @nkolba @chedzoir what I would love to see is something like the following (based on Nick's new simplified API): const myChannel = fdc3.getOrCreateChannel("myChannel");
const listener = myChannel.addContextListener("fdc3.instrument", instrument => {
// do something with instrument
// it can be strongly typed because we know its shape definitively
}); The key point for me is that this type of filtering allows:
Without being able to filter by type, the code would look like this: const listener = myChannel.addContextListener(context => {
if (context.type === "fdc3.instrument") {
const instrument = <Instrument>context;
// do something with instrument
} else if (context.type === "fdc3.contact") {
const contact = <Contact>context;
// do something with contact
}
}); Imagine having to do this countless times. The above is also why I am not really in favour of an array of context types, as you would have something very similar, i.e. no definitive shape of context data: const listener = myChannel.addContextListener(
["fdc.instrument", "fdc3.contact"],
context => {
if (context.type === "fdc3.instrument") {
const instrument = <Instrument>context;
// do something with instrument
} else if (context.type === "fdc3.contact") {
const contact = <Contact>context;
// do something with contact
}
}
); For this use case, I much prefer: const instrumentListener = myChannel.addContextListener("fdc3.instrument", instrument => {
// do something with instrument
});
const contactListener = myChannel.addContextListener("fdc3.contact", contact => {
// do something with contact
}); This achieves the same result as the array use case, while allowing the code to still be strongly typed, and at the same time it is much easier code to read and write, which is always a good thing. |
For the record, I think FDC3 should only allow filtering of context by the type property in listeners. The reason for this is that I think filtering by type allows the needed flexibility, if any further filtering is required (e.g. by delving into the id bag, this belongs inside the handler), e.g.: const listener = myChannel.addContextListener("fdc3.instrument", instrument => {
if (instrument.ticker) {
// display ticker
}
}); |
I don't see why this should be the case at all. The implication of filtering by type is simply that there is one truth for each context type, e.g.: const instrument = await myChannel.getCurrentValue(`fdc3.instrument`);
const contact = await myChannel.getCurrentValue(`fdc3.contact`);` I really like the symmetry of this, both with the concept of context data with a unique The implication is that instead of maintaining the latest value, the desktop agent has to maintain a map of latest values for each context type. This is a straight-forward expansion of the behaviour. |
To add to @rikoe's comment. A lot of this probably boils down to how we consider the current context. Is the current context just one context item or is it a combination? I've seen uses cases where people require the ability to have different context types active as current context. Do these live on different channels? So you need to listen to multiple channels, at which point this is moot. It may be that different people expect the channels to work differently, and as a group we ought to be clear what is the expectation and then from that it'd fall out. |
@chedzoir have we addressed everything with the latest changes? See https://fdc3.finos.org/docs/next/api/Channel and https://github.com/finos/FDC3/blob/master/src/api/interface.ts. If so, can we close this issue? |
Addressed with latest context filtering additions. |
There a couple of alterations that I'd suggest making to the API following my attempts at implementing it within our setup and how we expect it will actually get used
Can the default channel be be hidden behind a
getter
that returns a promise. That would make it's use consistent with thegetOrCreate
andgetSystemChannels
.Could we modify the
addBroadcastListener
to take an optional array of context types. Then the interop broker would only notify the listener in the event of one of those specified types being transmitted.This gives the following advantages
There is a downside here in that the channel will need to keep a history of the last received item by type, instead of just the last item - but that would just be a case of holding them within a map
Following on from 2, we would then need to add the same context type to the
getCurrentContext
methodIn context of a requirement that we have with regards to window based channel selectors, and following on from https://github.com/FDC3/FDC3/issues/118 I would propose the following approach to managing window selectors
On the channels module in https://github.com/FDC3/FDC3/blob/master/src/api/channel/channel.ts
add a function something along the lines of
public addWindowChannelListener(listener: (event: {channel: Channel; context: Context}) => void, types: string[]): DesktopAgent.Listener;
Then the application does not need to know about or worry about the action of selecting a channel. The swapping between channels can be handled within the broker/router code.
If the user sets the channel to "off" then the application just doesn't receive anything
A
DesktopAgent.Listener
is returned should the application decide that it wishes explicitly stop receiving anything regardless.The text was updated successfully, but these errors were encountered: