-
Notifications
You must be signed in to change notification settings - Fork 535
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
Move events library to core-interfaces and core-utils #23037
Closed
sonalideshpandemsft
wants to merge
24
commits into
microsoft:main
from
sonalideshpandemsft:mv-events-library
Closed
Changes from 21 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
8824e23
wip
sonalideshpandemsft 5c5c343
comment tests and build core-interface
sonalideshpandemsft 3375d11
wip
sonalideshpandemsft 9bf973a
fix lock file
sonalideshpandemsft d2e6bc1
wip
sonalideshpandemsft d6fa82e
Merge remote-tracking branch 'origin' into mv-events-library
sonalideshpandemsft c03bcb5
wip
sonalideshpandemsft 02d5f2f
move events to core-utils
sonalideshpandemsft b15eb27
Delete interop.ts as it's unused
sonalideshpandemsft 43fbee8
fix CI failure
sonalideshpandemsft b4ea361
mark eventemitter as internal
sonalideshpandemsft fa229a3
update imports in presence package
sonalideshpandemsft 744cef7
fix eslint errors
sonalideshpandemsft 512667e
Merge branch 'main' into mv-events-library
sonalideshpandemsft 50a415f
nits
sonalideshpandemsft 28d5f65
feedback wip
sonalideshpandemsft 9259cc8
feedback wip
sonalideshpandemsft 9abc1ab
wip
sonalideshpandemsft c49f3c7
Merge remote-tracking branch 'origin' into mv-events-library
sonalideshpandemsft b84034c
move tests
sonalideshpandemsft 3ec50b1
split tests
sonalideshpandemsft 9f560f9
move impl to client-utils
sonalideshpandemsft 135412a
Merge remote-tracking branch 'origin' into mv-events-library
sonalideshpandemsft 9d254e9
Merge remote-tracking branch 'origin' into mv-events-library
sonalideshpandemsft 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
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
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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/*! | ||
* Copyright (c) Microsoft Corporation and contributors. All rights reserved. | ||
* Licensed under the MIT License. | ||
*/ | ||
|
||
import type { Listeners } from "./listeners.js"; | ||
|
||
/** | ||
* Interface for an event emitter that can emit typed events to subscribed listeners. | ||
* @internal | ||
*/ | ||
export interface IEmitter<TListeners extends Listeners<TListeners>> { | ||
/** | ||
* Emits an event with the specified name and arguments, notifying all subscribers by calling their registered listener functions. | ||
* @param eventName - the name of the event to fire | ||
* @param args - the arguments passed to the event listener functions | ||
*/ | ||
emit<K extends keyof Listeners<TListeners>>( | ||
eventName: K, | ||
...args: Parameters<TListeners[K]> | ||
): void; | ||
|
||
/** | ||
* Emits an event with the specified name and arguments, notifying all subscribers by calling their registered listener functions. | ||
* It also collects the return values of all listeners into an array. | ||
* | ||
* Warning: This method should be used with caution. It deviates from the standard event-based integration pattern as creates substantial coupling between the emitter and its listeners. | ||
* For the majority of use-cases it is recommended to use the standard {@link IEmitter.emit} functionality. | ||
* @param eventName - the name of the event to fire | ||
* @param args - the arguments passed to the event listener functions | ||
* @returns An array of the return values of each listener, preserving the order listeners were called. | ||
*/ | ||
emitAndCollect<K extends keyof Listeners<TListeners>>( | ||
eventName: K, | ||
...args: Parameters<TListeners[K]> | ||
): ReturnType<TListeners[K]>[]; | ||
} | ||
|
||
/** | ||
* Called when the last listener for `eventName` is removed. | ||
* Useful for determining when to clean up resources related to detecting when the event might occurs. | ||
* @internal | ||
*/ | ||
export type NoListenersCallback<TListeners extends object> = ( | ||
eventName: keyof Listeners<TListeners>, | ||
) => void; | ||
|
||
/** | ||
* Allows querying if an object has listeners. | ||
* @sealed | ||
* @internal | ||
*/ | ||
export interface HasListeners<TListeners extends Listeners<TListeners>> { | ||
/** | ||
* When no `eventName` is provided, returns true iff there are any listeners. | ||
* | ||
* When `eventName` is provided, returns true iff there are listeners for that event. | ||
* | ||
* @remarks | ||
* This can be used to know when its safe to cleanup data-structures which only exist to fire events for their listeners. | ||
*/ | ||
hasListeners(eventName?: keyof Listeners<TListeners>): boolean; | ||
} | ||
|
||
/** | ||
* Subset of Map interface. | ||
* @internal | ||
*/ | ||
export interface MapGetSet<K, V> { | ||
get(key: K): V | undefined; | ||
set(key: K, value: V): void; | ||
} | ||
|
||
/** | ||
* A dictionary whose values are keyed off of two objects (key1, key2). | ||
* As it is a nested map, size() will return the number of distinct key1s. | ||
* If you need constant-time access to the number of values, use SizedNestedMap instead. | ||
* | ||
* This code assumes values will not be undefined (keys can be undefined). | ||
* @internal | ||
*/ | ||
export type NestedMap<Key1, Key2, Value> = Map<Key1, Map<Key2, Value>>; |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/*! | ||
* Copyright (c) Microsoft Corporation and contributors. All rights reserved. | ||
* Licensed under the MIT License. | ||
*/ | ||
|
||
export type { | ||
IEmitter, | ||
NoListenersCallback, | ||
HasListeners, | ||
MapGetSet, | ||
NestedMap, | ||
} from "./emitter.js"; | ||
|
||
export type { | ||
Listeners, | ||
Listenable, | ||
Off, | ||
IsListener, | ||
} from "./listeners.js"; |
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
File renamed without changes.
Oops, something went wrong.
Oops, something went wrong.
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.
iff
might have been a deliberate abbreviation of "if and only if" but I think in this context it doesn't make a difference.