Skip to content
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

Async listener and private channel events #1305

Merged
merged 15 commits into from
Sep 5, 2024

Conversation

kriswest
Copy link
Contributor

@kriswest kriswest commented Aug 1, 2024

resolves #1294
resolves #1300

  • Makes Listener.unsubscribe() async (the return type is changed from void to Promise<void>) for consistency with the rest of the API.
  • Adds an async addEventListener function to the PrivateChannel API to replace the deprecated, synchronous onAddContextListener, onUnsubscribe and onDisconnect functions and to keep consistency with the DesktopAgent API.
  • Deprecates PrivateChannel's synchronous onAddContextListener, onUnsubscribe and onDisconnect functions in favour of an async addEventListener function consistent with the one added to DesktopAgent in Add event listener support to the Desktop Agent API #1207
  • Adds missing Changle log entry for Add event listener support to the Desktop Agent API #1207

See previews at:

Copy link

netlify bot commented Aug 1, 2024

Deploy Preview for fdc3 ready!

Name Link
🔨 Latest commit 2ed30e6
🔍 Latest deploy log https://app.netlify.com/sites/fdc3/deploys/66d9b813dbd4f100088f0f01
😎 Deploy Preview https://deploy-preview-1305--fdc3.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@kriswest kriswest requested review from a team August 1, 2024 23:17
@kriswest
Copy link
Contributor Author

kriswest commented Aug 1, 2024

@Roaders @robmoffat This PR addresses the async API call issues you both raised. Let me know what you think.

@robmoffat
Copy link
Member

I like what you did here to unify the event listener stuff. I guess we're committing to this for 2.2 then?
We haven't actually discussed the listener changes in any meetings yet though

Copy link
Contributor Author

kriswest commented Aug 2, 2024

no we haven't. that would need to happen at the next meeting, having the pr and docs preview in hand makes it a lot easier to show the change however!

k

@Roaders
Copy link
Contributor

Roaders commented Aug 2, 2024

This looks good to me. I don't think that there is any easy way to test this in my local code other than building the .tgz myself and manually installing it in my project right?

Copy link
Contributor Author

kriswest commented Aug 2, 2024

Correct. Its easy enough todo however, checkout the relevant branch, run npm run pack which will build the project and then pack the tarball for you. Then simply npm install <path to tarball> in the project where you want to use it.

@kriswest kriswest added enhancement New feature or request api FDC3 API Working Group deprecation Deprecating or removing features post deprecation labels Aug 2, 2024
@kriswest
Copy link
Contributor Author

kriswest commented Aug 2, 2024

P.S. @Roaders if you try to do that with the FDC3 for Web PR, note that I haven't got around to adding BrowserTypes.to the exports in index.ts yet. It'll probably conflict with existing API exports so we'll probably need to export it as 'BrowserTypes' the same we do with BridgingTypes.

@kriswest
Copy link
Contributor Author

@Roaders @bingenito @hughtroeger I'll put this on the SWG agenda to look at this week. Would love to get some reviews on it.

*/
export type EventHandler = (event: FDC3Event) => void;
export type EventHandler = (event: FDC3Event | PrivateChannelEvent ) => void;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a good common base type or marker interface recommendation for this in other languages?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it basically just a string and object properties?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah the dreaded union type again.

The event types are just strings really, we're just using the enums to govern the set as we do with errors - they are all that really differs. The type names are mutually exclusive between the fdc3 interface events and privateChannel interface events, but it felt like they should be different enums.

I haven't included a common anscestor for the two event types (FDC3Event & PrivateChannelEvent), which is I guess what you are after! I can go add that and have both extend it with specific enums for the types. That would mean EventHandler could use that ancestor here instead...

I'll go take a look at this - I suspect typescript enums are going to make the above more difficult than it should be... Might have to switch to string unions...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can go with a simple event args type with string and object on C# side but it might be fragile with future changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checkout c47b7b2
Hopefully it'll alleviate your issue here by introducing a base ApiEvent type that the others restrict down to specific messages.

Copy link
Contributor Author

Working on an update that remove the enums as then you can have a workable inheritance structure

src/api/Events.ts Outdated Show resolved Hide resolved
@kriswest
Copy link
Contributor Author

Updated to keep event type names style consistent (camelCase) as agreed at SWG meeting 22/08/24. Also, consent was received to make these changes once they are passed through the review of maintainers/editors.

@kriswest kriswest requested review from bingenito and a team August 23, 2024 11:06
bingenito
bingenito previously approved these changes Sep 3, 2024
Copy link
Contributor Author

@kriswest kriswest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This did not merge well with with the .NET PR, particularly in the PrivateChannel.md file - where some work is needed from @bingenito to fill in .NET examples.

THere is also a syntax error somewhere in PrivateChannel.md that I can't find, that is preventing the site from compiling...

Comment on lines +26 to 33
// functions
addEventListener(type: PrivateChannelEventTypes | null, handler: EventHandler): Promise<Listener>;
disconnect(): Promise<void>;

//deprecated functions
onAddContextListener(handler: (contextType?: string) => void): Listener;
onUnsubscribe(handler: (contextType?: string) => void): Listener;
onDisconnect(handler: () => void): Listener;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bingenito, need to replicate this in the .NET block below

channel.broadcast({ type: "price", price});
});
});
const addContextListener = channel.addEventListener("addContextListener",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bingenito need to replicate switch to new function in .NET version below

const unsubscribeListener = channel.onUnsubscribe((contextType) => {
feed.stop(symbol);
});
const unsubscribeListener = channel.addEventListener("unsubscribe",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bingenito need to replicate switch to new function in .NET version below

const disconnectListener = channel.onDisconnect(() => {
feed.stop(symbol);
});
const disconnectListener = channel.addEventListener("disconnect",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bingenito need to replicate switch to new function in .NET version below

const listener = result.addContextListener("price", (quote) => console.log(quote));
//if it's a PrivateChannel
if (result.type == "private") {
result.addEventListener("disconnect", () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bingenito need to replicate switch to new function in .NET version below

```csharp
IListener OnAddContextListener(Action<string?> handler);
```
Not implemented
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bingenito need to function definition here

@bingenito
Copy link
Member

bingenito commented Sep 3, 2024

This did not merge well with with the .NET PR, particularly in the PrivateChannel.md file - where some work is needed from @bingenito to fill in .NET examples.

THere is also a syntax error somewhere in PrivateChannel.md that I can't find, that is preventing the site from compiling...

This was never implemented. The pending work is under #1318 to done once this is merged.

@bingenito
Copy link
Member

This did not merge well with with the .NET PR, particularly in the PrivateChannel.md file - where some work is needed from @bingenito to fill in .NET examples.

THere is also a syntax error somewhere in PrivateChannel.md that I can't find, that is preventing the site from compiling...

It seems as though it is trying to transpile the markdown rather than build docs.

@kriswest
Copy link
Contributor Author

kriswest commented Sep 4, 2024

This did not merge well with with the .NET PR, particularly in the PrivateChannel.md file - where some work is needed from @bingenito to fill in .NET examples.
THere is also a syntax error somewhere in PrivateChannel.md that I can't find, that is preventing the site from compiling...

It seems as though it is trying to transpile the markdown rather than build docs.

Looks like it - but I think theres a syntax error somewhere that is making it think that the code block is markup it needs to process. Its fine with other code blocks on that page so it's likely a stray or missing character I'm just not seeing...

@kriswest
Copy link
Contributor Author

kriswest commented Sep 4, 2024

This did not merge well with with the .NET PR, particularly in the PrivateChannel.md file - where some work is needed from @bingenito to fill in .NET examples.
THere is also a syntax error somewhere in PrivateChannel.md that I can't find, that is preventing the site from compiling...

This was never implemented. The pending work is under #1318 to done once this is merged.

SHall I just go and add the tab but put Not implemented yet in it?

@bingenito
Copy link
Member

Unless you think it is causing this issue I wouldn't bother as I'll do it with a PR after this merge. I think there is a different issue here perhaps with mismatched tags that I'm looking at. The syntax of that example is the same in the merged PR.

@bingenito bingenito force-pushed the async-listener-and-PrivateChannel-events branch from aff0c68 to 4f027b8 Compare September 4, 2024 11:16
@bingenito
Copy link
Member

That force push was for a git commit amend of my last commit message

bingenito
bingenito previously approved these changes Sep 4, 2024
@kriswest kriswest requested a review from a team September 4, 2024 13:40
hughtroeger
hughtroeger previously approved these changes Sep 4, 2024
@kriswest
Copy link
Contributor Author

kriswest commented Sep 5, 2024

@hughtroeger no worries - thanks for getting to another one!

I spotted a syntax error (another stray space char):
image

Fixed, could you re-approve @hughtroeger ?

@kriswest kriswest dismissed stale reviews from hughtroeger and bingenito via 2ed30e6 September 5, 2024 13:54
@kriswest kriswest merged commit c3f52ea into main Sep 5, 2024
6 checks passed
@kriswest kriswest deleted the async-listener-and-PrivateChannel-events branch September 5, 2024 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api FDC3 API Working Group deprecation Deprecating or removing features post deprecation enhancement New feature or request needs-conformance-test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make Listener.unsubscribe() async for consistency Inconsistent Use of Promises
5 participants