Skip to content

Commit

Permalink
move impl to client-utils
Browse files Browse the repository at this point in the history
  • Loading branch information
sonalideshpandemsft committed Nov 15, 2024
1 parent 3ec50b1 commit 9f560f9
Show file tree
Hide file tree
Showing 30 changed files with 48 additions and 40 deletions.
2 changes: 1 addition & 1 deletion layerInfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
},
"Core-Utils": {
"packages": ["@fluidframework/core-utils"],
"deps": ["Core-Interfaces"]
"deps": []
},
"Client-Utils": {
"packages": ["@fluid-internal/client-utils"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function getOrCreate<K, V>(map: MapGetSet<K, V>, key: K, defaultValue: (key: K)
* ```
* @internal
*/
export class EventEmitter<TListeners extends Listeners<TListeners>>
export class CustomEventEmitter<TListeners extends Listeners<TListeners>>
implements Listenable<TListeners>, HasListeners<TListeners>
{
protected readonly listeners = new Map<
Expand Down Expand Up @@ -170,7 +170,7 @@ export class EventEmitter<TListeners extends Listeners<TListeners>>
* @internal
*/
class ComposableEventEmitter<TListeners extends Listeners<TListeners>>
extends EventEmitter<TListeners>
extends CustomEventEmitter<TListeners>
implements IEmitter<TListeners>
{
public constructor(noListeners?: NoListenersCallback<TListeners>) {
Expand All @@ -196,7 +196,7 @@ class ComposableEventEmitter<TListeners extends Listeners<TListeners>>
* Create a {@link @fluidframework/core-interfaces#Listenable} that can be instructed to emit events via the {@link @fluidframework/core-interfaces#IEmitter} interface.
*
* A class can delegate handling {@link @fluidframework/core-interfaces#Listenable} to the returned value while using it to emit the events.
* See also {@link EventEmitter} which be used as a base class to implement {@link @fluidframework/core-interfaces#Listenable} via extension.
* See also {@link CustomEventEmitter} which be used as a base class to implement {@link @fluidframework/core-interfaces#Listenable} via extension.
* @example Forwarding events to the emitter
* ```typescript
* interface MyEvents {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@

export {
createEmitter,
EventEmitter,
CustomEventEmitter,
} from "./emitter.js";
2 changes: 2 additions & 0 deletions packages/common/client-utils/src/indexBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ export {
TypedEventEmitter,
type TypedEventTransform,
} from "./typedEventEmitter.js";

export { createEmitter, CustomEventEmitter } from "./events/index.js";
2 changes: 2 additions & 0 deletions packages/common/client-utils/src/indexNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ export {
TypedEventEmitter,
type TypedEventTransform,
} from "./typedEventEmitter.js";

export { createEmitter, CustomEventEmitter } from "./events/index.js";
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import { strict as assert } from "node:assert";

import type { Listenable } from "@fluidframework/core-interfaces/internal";

import { EventEmitter, createEmitter } from "@fluidframework/core-utils/internal";
import { CustomEventEmitter, createEmitter } from "../../events/index.js";

interface TestEvents {
open: () => void;
close: (error: boolean) => void;
compute: (input: string) => string;
}

describe("EventEmitter", () => {
describe("CustomEventEmitter", () => {
it("emits events", () => {
const emitter = createEmitter<TestEvents>();
const log: string[] = [];
Expand Down Expand Up @@ -256,7 +256,7 @@ describe("EventEmitter", () => {

/**
*
* The below classes correspond to the examples given in {@link EventEmitter} to ensure that they compile.
* The below classes correspond to the examples given in {@link CustomEventEmitter} to ensure that they compile.
*
* Provides an API for subscribing to and listening to events.
*
Expand All @@ -273,7 +273,7 @@ interface MyEvents {
/**
* @example Extending this class
*/
export class MyInheritanceClass extends EventEmitter<MyEvents> {
export class MyInheritanceClass extends CustomEventEmitter<MyEvents> {
private load(): number[] {
this.emit("loaded");
const results: number[] = this.emitAndCollect("computed");
Expand Down
2 changes: 1 addition & 1 deletion packages/common/core-interfaces/src/events/listeners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export type Listeners<T extends object> = {
* error: (errorCode: number) => void;
* }>
* ```
* {@link createEmitter} can help implement this interface via delegation.
* {@link @fluid-internal/client-utils#createEmitter} can help implement this interface via delegation.
*
* @sealed
* @public
Expand Down
3 changes: 0 additions & 3 deletions packages/common/core-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,6 @@
],
"temp-directory": "nyc/.nyc_output"
},
"dependencies": {
"@fluidframework/core-interfaces": "workspace:~"
},
"devDependencies": {
"@arethetypeswrong/cli": "^0.16.4",
"@biomejs/biome": "~1.9.3",
Expand Down
4 changes: 0 additions & 4 deletions packages/common/core-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,3 @@ export { PromiseTimer, setLongTimeout, Timer } from "./timer.js";
export { unreachableCase } from "./unreachable.js";
export { isObject, isPromiseLike } from "./typesGuards.js";
export { oob } from "./oob.js";
export {
createEmitter,
EventEmitter,
} from "./events/index.js";
2 changes: 1 addition & 1 deletion packages/dds/tree/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
"test:memory-profiling:report": "mocha --config ./src/test/memory/.mocharc.cjs",
"test:mocha": "npm run test:mocha:esm && echo skipping cjs to avoid overhead - npm run test:mocha:cjs",
"test:mocha:cjs": "cross-env MOCHA_SPEC=dist/test mocha",
"test:mocha:esm": "mocha --recursive ./lib/test/events --exit",
"test:mocha:esm": "mocha",
"test:mocha:verbose": "cross-env FLUID_TEST_VERBOSE=1 npm run test:mocha",
"test:snapshots:regen": "pnpm test:mocha:esm --snapshot",
"test:stress": "cross-env FUZZ_TEST_COUNT=20 FUZZ_STRESS_RUN=normal mocha --ignore \"lib/test/memory/**/*\" --recursive \"lib/test/**/*.spec.js\"",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { BTree } from "@tylerbu/sorted-btree-es6";

import { createEmitter } from "@fluidframework/core-utils/internal";
import { createEmitter } from "@fluid-internal/client-utils";
import type { Listenable } from "@fluidframework/core-interfaces/internal";
import { compareStrings } from "../../util/index.js";

Expand Down
3 changes: 2 additions & 1 deletion packages/dds/tree/src/core/tree/anchorSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

/* eslint-disable @typescript-eslint/no-non-null-assertion */

import { assert, createEmitter } from "@fluidframework/core-utils/internal";
import { assert } from "@fluidframework/core-utils/internal";
import { createEmitter } from "@fluid-internal/client-utils";

import type { Listenable } from "@fluidframework/core-interfaces/internal";
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
* Licensed under the MIT License.
*/

import { assert, oob, createEmitter } from "@fluidframework/core-utils/internal";
import { assert, oob } from "@fluidframework/core-utils/internal";
import type { Listenable } from "@fluidframework/core-interfaces/internal";
import { createEmitter } from "@fluid-internal/client-utils";

import {
type Anchor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
* Licensed under the MIT License.
*/

import { assert, createEmitter } from "@fluidframework/core-utils/internal";
import { assert } from "@fluidframework/core-utils/internal";
import type { Listenable } from "@fluidframework/core-interfaces/internal";
import { createEmitter } from "@fluid-internal/client-utils";

import {
type Anchor,
Expand Down
4 changes: 2 additions & 2 deletions packages/dds/tree/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,5 +241,5 @@ export type {

export {
createEmitter,
EventEmitter,
} from "@fluidframework/core-utils/internal";
CustomEventEmitter,
} from "@fluid-internal/client-utils";
3 changes: 2 additions & 1 deletion packages/dds/tree/src/shared-tree-core/branch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
* Licensed under the MIT License.
*/

import { assert, oob, createEmitter } from "@fluidframework/core-utils/internal";
import { assert, oob } from "@fluidframework/core-utils/internal";
import type { Listenable } from "@fluidframework/core-interfaces/internal";
import { type TelemetryEventBatcher, measure } from "@fluidframework/telemetry-utils/internal";
import { createEmitter } from "@fluid-internal/client-utils";

import {
type BranchRebaseResult,
Expand Down
3 changes: 2 additions & 1 deletion packages/dds/tree/src/shared-tree-core/editManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
* Licensed under the MIT License.
*/

import { assert, createEmitter } from "@fluidframework/core-utils/internal";
import { assert } from "@fluidframework/core-utils/internal";
import type { SessionId } from "@fluidframework/id-compressor";
import { createEmitter } from "@fluid-internal/client-utils";
import { BTree } from "@tylerbu/sorted-btree-es6";

import {
Expand Down
3 changes: 2 additions & 1 deletion packages/dds/tree/src/shared-tree/schematizingTreeView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
* Licensed under the MIT License.
*/

import { assert, createEmitter } from "@fluidframework/core-utils/internal";
import { assert } from "@fluidframework/core-utils/internal";
import { UsageError } from "@fluidframework/telemetry-utils/internal";
import { createEmitter } from "@fluid-internal/client-utils";

import {
AllowedUpdateType,
Expand Down
3 changes: 2 additions & 1 deletion packages/dds/tree/src/shared-tree/sharedTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License.
*/

import { assert, unreachableCase, createEmitter } from "@fluidframework/core-utils/internal";
import { assert, unreachableCase } from "@fluidframework/core-utils/internal";
import type {
HasListeners,
IEmitter,
Expand All @@ -18,6 +18,7 @@ import type {
} from "@fluidframework/datastore-definitions/internal";
import type { ISharedObject } from "@fluidframework/shared-object-base/internal";
import { UsageError } from "@fluidframework/telemetry-utils/internal";
import { createEmitter } from "@fluid-internal/client-utils";

import { type ICodecOptions, noopValidator } from "../codec/index.js";
import {
Expand Down
4 changes: 3 additions & 1 deletion packages/dds/tree/src/shared-tree/treeCheckout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License.
*/

import { assert, oob, createEmitter } from "@fluidframework/core-utils/internal";
import { assert, oob } from "@fluidframework/core-utils/internal";
import type {
HasListeners,
IEmitter,
Expand All @@ -14,6 +14,8 @@ import {
UsageError,
type ITelemetryLoggerExt,
} from "@fluidframework/telemetry-utils/internal";
import { createEmitter } from "@fluid-internal/client-utils";

import { noopValidator } from "../codec/index.js";
import {
type Anchor,
Expand Down
3 changes: 2 additions & 1 deletion packages/dds/tree/src/simple-tree/core/treeNodeKernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
*/

import type { Listenable, Off } from "@fluidframework/core-interfaces/internal";
import { assert, Lazy, createEmitter } from "@fluidframework/core-utils/internal";
import { assert, Lazy } from "@fluidframework/core-utils/internal";
import { createEmitter } from "@fluid-internal/client-utils";
import type { TreeNode, Unhydrated } from "./types.js";
import {
anchorSlot,
Expand Down
3 changes: 2 additions & 1 deletion packages/dds/tree/src/simple-tree/core/unhydratedFlexTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
* Licensed under the MIT License.
*/

import { assert, createEmitter, oob } from "@fluidframework/core-utils/internal";
import { createEmitter } from "@fluid-internal/client-utils";
import { assert, oob } from "@fluidframework/core-utils/internal";
import type { Listenable } from "@fluidframework/core-interfaces/internal";
import { UsageError } from "@fluidframework/telemetry-utils/internal";

Expand Down
2 changes: 1 addition & 1 deletion packages/dds/tree/src/test/events/events.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { strict as assert } from "node:assert";

import { validateAssertionError } from "@fluidframework/test-runtime-utils/internal";

import { createEmitter } from "@fluidframework/core-utils/internal";
import { createEmitter } from "@fluid-internal/client-utils";

interface TestEvents {
open: () => void;
Expand Down
1 change: 1 addition & 0 deletions packages/framework/presence/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
"temp-directory": "nyc/.nyc_output"
},
"dependencies": {
"@fluid-internal/client-utils": "workspace:~",
"@fluidframework/container-definitions": "workspace:~",
"@fluidframework/container-loader": "workspace:~",
"@fluidframework/container-runtime-definitions": "workspace:~",
Expand Down
2 changes: 1 addition & 1 deletion packages/framework/presence/src/latestMapValueManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License.
*/

import { createEmitter } from "@fluidframework/core-utils/internal";
import { createEmitter } from "@fluid-internal/client-utils";

import type { ValueManager } from "./internalTypes.js";
import type { LatestValueControls } from "./latestValueControls.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/framework/presence/src/latestValueManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License.
*/

import { createEmitter } from "@fluidframework/core-utils/internal";
import { createEmitter } from "@fluid-internal/client-utils";

import type { ValueManager } from "./internalTypes.js";
import { brandedObjectEntries } from "./internalTypes.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/framework/presence/src/notificationsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License.
*/

import { createEmitter } from "@fluidframework/core-utils/internal";
import { createEmitter } from "@fluid-internal/client-utils";

import type { ValueManager } from "./internalTypes.js";
import type { ISessionClient } from "./presence.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/framework/presence/src/presenceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* Licensed under the MIT License.
*/

import { createEmitter } from "@fluid-internal/client-utils";
import type { IEmitter } from "@fluidframework/core-interfaces/internal";
import { createEmitter } from "@fluidframework/core-utils/internal";
import { createSessionId } from "@fluidframework/id-compressor/internal";
import type {
ITelemetryLoggerExt,
Expand Down
7 changes: 3 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9f560f9

Please sign in to comment.