-
Notifications
You must be signed in to change notification settings - Fork 119
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
Context Clearing #1379
Open
kemerava
wants to merge
3
commits into
finos:main
Choose a base branch
from
kemerava:feature/context-clearing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Context Clearing #1379
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,7 @@ interface Channel { | |
broadcast(context: Context): Promise<void>; | ||
getCurrentContext(contextType?: string): Promise<Context|null>; | ||
addContextListener(contextType: string | null, handler: ContextHandler): Promise<Listener>; | ||
clearContext(contextType?: string): Promise<void>; | ||
|
||
//deprecated functions | ||
/** | ||
|
@@ -57,6 +58,7 @@ interface IChannel: IIntentResult | |
Task Broadcast(IContext context); | ||
Task<IContext?> GetCurrentContext(string? contextType); | ||
Task<IListener> AddContextListener<T>(string? contextType, ContextHandler<T> handler) where T : IContext; | ||
Task ClearContext(string? contextType); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
``` | ||
|
||
|
@@ -431,6 +433,99 @@ catch (Exception ex) | |
- [`broadcast`](#broadcast) | ||
- [`addContextListener`](#addcontextlistener) | ||
|
||
### `clearContext` | ||
|
||
<Tabs groupId="lang"> | ||
<TabItem value="ts" label="TypeScript/JavaScript"> | ||
|
||
```ts | ||
public clearContext(contextType?: string): Promise<void>; | ||
``` | ||
|
||
</TabItem> | ||
<TabItem value="dotnet" label=".NET"> | ||
|
||
```csharp | ||
Task ClearContext(string? contextType); | ||
``` | ||
|
||
</TabItem> | ||
</Tabs> | ||
|
||
Used to clear the specified context type if provided, otherwise, clear all context types present in the channel. The Desktop Agent MUST update its internal representation of the context in the channel and ensure that subsequent calls to [`getCurrentContext`](#getcurrentcontext) and any new joiners to that channel (through [`joinUserChannel`](DesktopAgent#joinUserChannel) or [`addContextListener`](DesktopAgent#addContextListener)) will not receive anything for either specified context type or the most recent context until new context has been broadcast to the channel. | ||
Desktop Agents MUST also immediately broadcast the [`fdc3.nothing`](../../context/ref/Nothing.md/#nothing) type, which applications may listen to to be notified of the cleared context. If a `contextType` parameter was provided, then the `contextType` field will be set to that type, otherwise, it is omitted. | ||
|
||
|
||
**Examples:** | ||
|
||
Without specifying a context type: | ||
|
||
<Tabs groupId="lang"> | ||
<TabItem value="ts" label="TypeScript/JavaScript"> | ||
|
||
```ts | ||
try { | ||
const context = await channel.clearContext(); | ||
} catch (err: ChannelError) { | ||
// handle error | ||
} | ||
``` | ||
|
||
</TabItem> | ||
<TabItem value="dotnet" label=".NET"> | ||
|
||
```csharp | ||
try | ||
{ | ||
var context = await channel.ClearContext(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
// handle error | ||
} | ||
``` | ||
|
||
</TabItem> | ||
</Tabs> | ||
|
||
Specifying a context type: | ||
|
||
<Tabs groupId="lang"> | ||
<TabItem value="ts" label="TypeScript/JavaScript"> | ||
|
||
```ts | ||
try { | ||
const contact = await channel.clearContext('fdc3.contact'); | ||
} catch (err: ChannelError) { | ||
// handler error | ||
} | ||
``` | ||
|
||
</TabItem> | ||
<TabItem value="dotnet" label=".NET"> | ||
|
||
```csharp | ||
try | ||
{ | ||
var context = await channel.ClearContext("fdc3.contact"); | ||
} | ||
catch (Exception ex) | ||
{ | ||
// handle error | ||
} | ||
``` | ||
|
||
</TabItem> | ||
</Tabs> | ||
|
||
|
||
**See also:** | ||
|
||
- [`getCurrentContext`](#getcurrentcontext) | ||
- [`addContextListener`](DesktopAgent#addContextListener) | ||
- [`joinUserChannel`](DesktopAgent#joinUserChannel) | ||
- [`fdc3.nothing`](../../context/ref/Nothing.md/#nothing) | ||
|
||
## Deprecated Functions | ||
|
||
### `addContextListener` (deprecated) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if we should require an explicit null argument (
contextType: string | null
) to clear all types - which would matchaddContectListener
or stick with this (matchinggetCurrentContext
). Either works of course.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To me it makes sense to keep it closer to getCurrentContext, because they seem most related to me, but happy to hear any thoughts/suggestions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a historical reason for
addContextListener
having an explicit null argument, thecontextType
argument was originally optional so thehandler
argument could be either first or second (when a type was specified). This was NOT good in practice so we moved to an explicitnull
argument and deprecated the single argument override:https://fdc3.finos.org/docs/2.0/api/ref/DesktopAgent#addcontextlistener-deprecated
We don't have that problem here, so I agree its fine as is (matching
getCurrentContext
).