Skip to content

Commit 5b40bf4

Browse files
Aqueduct: Add props object based constructor for DataObject Factories (#24527)
The current argument-based constructors for DataObjectFactory, and PureDataObjectFactory do not scale. They already have multiple optional arguments which leads to hard to read and understand code like: ``` private static readonly factory = new DataObjectFactory( DataObjectGrid.ComponentName, DataObjectGrid, [], {}, [...registryEntries], ); ``` Adding further argument would further increase the problems of the current approach. To allow for easier additions, i've added a property object base constructor to both DataObjectFactory, and PureDataObjectFactory: ``` private static readonly factory = new DataObjectFactory({ type: DataObjectGrid.ComponentName, ctor: DataObjectGrid, registryEntries: [...registryEntries], }); ``` I've also updated all existing usages. I primarily used co-pilot to do this in agentic mode with the follow prompts: - `you must search for the regex `new DataObjectFactory\([^{}]` and complete all those files. you should convert from the multiple parameters constructor to the single props based constructor. keep the same values when converting. ` - `you must search for the regex `new DataObjectFactory\($` and complete all those files. you should convert from the multiple parameters constructor to the single props based constructor. keep the same values when converting.`
1 parent 67afa66 commit 5b40bf4

File tree

85 files changed

+659
-625
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+659
-625
lines changed

examples/apps/attributable-map/src/dataObject.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,11 @@ export class HitCounter extends DataObject implements IHitCounter {
5353

5454
public static readonly Name = "@fluid-example/attributable-map";
5555

56-
private static readonly factory = new DataObjectFactory(
57-
HitCounter.Name,
58-
HitCounter,
59-
[AttributableMap.getFactory()],
60-
{},
61-
);
56+
private static readonly factory = new DataObjectFactory({
57+
type: HitCounter.Name,
58+
ctor: HitCounter,
59+
sharedObjects: [AttributableMap.getFactory()],
60+
});
6261

6362
public static getFactory(): DataObjectFactory<HitCounter> {
6463
return this.factory;

examples/apps/collaborative-textarea/src/fluid-object/index.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,11 @@ export class CollaborativeText extends DataObject {
2424

2525
public static readonly Name = "@fluid-example/collaborative-textarea";
2626

27-
private static readonly factory = new DataObjectFactory(
28-
CollaborativeText.Name,
29-
CollaborativeText,
30-
[SharedString.getFactory()],
31-
{},
32-
);
27+
private static readonly factory = new DataObjectFactory({
28+
type: CollaborativeText.Name,
29+
ctor: CollaborativeText,
30+
sharedObjects: [SharedString.getFactory()],
31+
});
3332

3433
public static getFactory(): DataObjectFactory<CollaborativeText> {
3534
return this.factory;

examples/apps/contact-collection/src/dataObject.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,7 @@ export class ContactCollection extends DataObject implements IContactCollection
103103
* The DataObjectFactory is used by Fluid Framework to instantiate our DataObject. We provide it with a unique name
104104
* and the constructor it will call. In this scenario, the third and fourth arguments are not used.
105105
*/
106-
export const ContactCollectionInstantiationFactory = new DataObjectFactory(
107-
"contact-collection",
108-
ContactCollection,
109-
[],
110-
{},
111-
);
106+
export const ContactCollectionInstantiationFactory = new DataObjectFactory({
107+
type: "contact-collection",
108+
ctor: ContactCollection,
109+
});

examples/apps/data-object-grid/src/dataObjectGrid.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,11 @@ export interface IDataObjectGridItem {
7373
export class DataObjectGrid extends DataObject implements IDataObjectGrid {
7474
public static readonly ComponentName = "@fluid-example/data-object-grid";
7575

76-
private static readonly factory = new DataObjectFactory(
77-
DataObjectGrid.ComponentName,
78-
DataObjectGrid,
79-
[],
80-
{},
81-
[...registryEntries],
82-
);
76+
private static readonly factory = new DataObjectFactory({
77+
type: DataObjectGrid.ComponentName,
78+
ctor: DataObjectGrid,
79+
registryEntries: [...registryEntries],
80+
});
8381

8482
public static getFactory() {
8583
return DataObjectGrid.factory;

examples/apps/task-selection/src/oldestClientDiceRoller.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,7 @@ export class OldestClientDiceRoller extends DataObject implements IDiceRoller {
106106
* The DataObjectFactory is used by Fluid Framework to instantiate our DataObject. We provide it with a unique name
107107
* and the constructor it will call. In this scenario, the third and fourth arguments are not used.
108108
*/
109-
export const OldestClientDiceRollerInstantiationFactory = new DataObjectFactory(
110-
"@fluid-example/oldest-client-dice-roller",
111-
OldestClientDiceRoller,
112-
[],
113-
{},
114-
);
109+
export const OldestClientDiceRollerInstantiationFactory = new DataObjectFactory({
110+
type: "@fluid-example/oldest-client-dice-roller",
111+
ctor: OldestClientDiceRoller,
112+
});

examples/apps/task-selection/src/taskManagerDiceRoller.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,8 @@ export class TaskManagerDiceRoller extends DataObject implements IDiceRoller {
115115
* The DataObjectFactory is used by Fluid Framework to instantiate our DataObject. We provide it with a unique name
116116
* and the constructor it will call. In this scenario, the third and fourth arguments are not used.
117117
*/
118-
export const TaskManagerDiceRollerInstantiationFactory = new DataObjectFactory(
119-
"@fluid-example/task-manager-dice-roller",
120-
TaskManagerDiceRoller,
121-
// Since TaskManager is a DDS, we need to register it for creation.
122-
[TaskManager.getFactory()],
123-
{},
124-
);
118+
export const TaskManagerDiceRollerInstantiationFactory = new DataObjectFactory({
119+
type: "@fluid-example/task-manager-dice-roller",
120+
ctor: TaskManagerDiceRoller,
121+
sharedObjects: [TaskManager.getFactory()],
122+
});

examples/benchmarks/bubblebench/baseline/src/main.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ export class Bubblebench extends DataObject {
3535
* To add a SharedSequence, SharedMap, or any other structure, put it in the array below.
3636
* @internal
3737
*/
38-
export const BubblebenchInstantiationFactory = new DataObjectFactory(
39-
Bubblebench.Name,
40-
Bubblebench,
41-
[],
42-
{},
43-
);
38+
export const BubblebenchInstantiationFactory = new DataObjectFactory({
39+
type: Bubblebench.Name,
40+
ctor: Bubblebench,
41+
});

examples/benchmarks/bubblebench/experimental-tree/src/main.tsx

+5-6
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,8 @@ export class Bubblebench extends DataObject {
8080
* To add a SharedSequence, SharedMap, or any other structure, put it in the array below.
8181
* @internal
8282
*/
83-
export const BubblebenchInstantiationFactory = new DataObjectFactory(
84-
Bubblebench.Name,
85-
Bubblebench,
86-
[SharedTree.getFactory(WriteFormat.v0_1_1)],
87-
{},
88-
);
83+
export const BubblebenchInstantiationFactory = new DataObjectFactory({
84+
type: Bubblebench.Name,
85+
ctor: Bubblebench,
86+
sharedObjects: [SharedTree.getFactory(WriteFormat.v0_1_1)],
87+
});

examples/benchmarks/bubblebench/ot/src/main.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,8 @@ export class Bubblebench extends DataObject {
7474
* To add a SharedSequence, SharedMap, or any other structure, put it in the array below.
7575
* @internal
7676
*/
77-
export const BubblebenchInstantiationFactory = new DataObjectFactory(
78-
Bubblebench.Name,
79-
Bubblebench,
80-
[SharedJson1.getFactory()],
81-
{},
82-
);
77+
export const BubblebenchInstantiationFactory = new DataObjectFactory({
78+
type: Bubblebench.Name,
79+
ctor: Bubblebench,
80+
sharedObjects: [SharedJson1.getFactory()],
81+
});

examples/benchmarks/bubblebench/shared-tree/src/bubblebench.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,8 @@ export class Bubblebench extends DataObject {
8585
* To add a SharedSequence, SharedMap, or any other structure, put it in the array below.
8686
* @internal
8787
*/
88-
export const BubblebenchInstantiationFactory = new DataObjectFactory(
89-
Bubblebench.Name,
90-
Bubblebench,
91-
[SharedTree.getFactory()], // This is fine for now but we will have to adjust this API later to allow control of write format
92-
{},
93-
);
88+
export const BubblebenchInstantiationFactory = new DataObjectFactory({
89+
type: Bubblebench.Name,
90+
ctor: Bubblebench,
91+
sharedObjects: [SharedTree.getFactory()],
92+
});

examples/data-objects/canvas/src/index.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@ import { CanvasView } from "./view.js";
1414
/**
1515
* @internal
1616
*/
17-
export const CanvasInstantiationFactory = new DataObjectFactory(
18-
"Canvas",
19-
Canvas,
20-
[Ink.getFactory()],
21-
{},
22-
);
17+
export const CanvasInstantiationFactory = new DataObjectFactory({
18+
type: "Canvas",
19+
ctor: Canvas,
20+
sharedObjects: [Ink.getFactory()],
21+
});
2322

2423
const canvasViewCallback = (canvas: Canvas): React.ReactElement =>
2524
React.createElement(CanvasView, { canvas });

examples/data-objects/clicker/src/index.tsx

+5-6
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,11 @@ export class ClickerReactView extends React.Component<ClickerProps, ClickerState
140140

141141
// ----- FACTORY SETUP -----
142142

143-
export const ClickerInstantiationFactory = new DataObjectFactory(
144-
ClickerName,
145-
Clicker,
146-
[SharedCounter.getFactory(), TaskManager.getFactory()],
147-
{},
148-
);
143+
export const ClickerInstantiationFactory = new DataObjectFactory({
144+
type: ClickerName,
145+
ctor: Clicker,
146+
sharedObjects: [SharedCounter.getFactory(), TaskManager.getFactory()],
147+
});
149148

150149
const clickerViewCallback = (clicker: Clicker) => <ClickerReactView clicker={clicker} />;
151150

examples/data-objects/diceroller/src/main.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ export const DiceRollerView: React.FC<IDiceRollerViewProps> = (
6767
export class DiceRoller extends DataObject implements IDiceRoller {
6868
public static readonly Name = "@fluid-example/dice-roller";
6969

70-
public static readonly factory = new DataObjectFactory(DiceRoller.Name, DiceRoller, [], {});
70+
public static readonly factory = new DataObjectFactory({
71+
type: DiceRoller.Name,
72+
ctor: DiceRoller,
73+
});
7174

7275
/**
7376
* initializingFirstTime is called only once, it is executed only by the first client to open the

examples/data-objects/monaco/src/index.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@ import { MonacoView } from "./view.js";
1313

1414
const monacoName = "@fluid-example/monaco";
1515

16-
const componentFactory = new DataObjectFactory(
17-
monacoName,
18-
MonacoRunner,
19-
[sequence.SharedString.getFactory()],
20-
{},
21-
);
16+
const componentFactory = new DataObjectFactory({
17+
type: monacoName,
18+
ctor: MonacoRunner,
19+
sharedObjects: [sequence.SharedString.getFactory()],
20+
});
2221

2322
const monacoViewCallback = (model: MonacoRunner): React.ReactElement =>
2423
React.createElement(MonacoView, { sharedString: model.text });

examples/data-objects/multiview/constellation-model/src/model.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,11 @@ export class Constellation extends DataObject implements IConstellation {
2323
return Constellation.factory;
2424
}
2525

26-
private static readonly factory = new DataObjectFactory(
27-
constellationName,
28-
Constellation,
29-
[],
30-
{},
31-
new Map([Coordinate.getFactory().registryEntry]),
32-
);
26+
private static readonly factory = new DataObjectFactory({
27+
type: constellationName,
28+
ctor: Constellation,
29+
registryEntries: new Map([Coordinate.getFactory().registryEntry]),
30+
});
3331

3432
protected async initializingFirstTime(): Promise<void> {
3533
this.root.set(starListKey, []);

examples/data-objects/multiview/coordinate-model/src/model.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,10 @@ export class Coordinate extends DataObject implements ICoordinate {
2121
return Coordinate.factory;
2222
}
2323

24-
private static readonly factory = new DataObjectFactory(
25-
Coordinate.ComponentName,
26-
Coordinate,
27-
[],
28-
{},
29-
);
24+
private static readonly factory = new DataObjectFactory({
25+
type: Coordinate.ComponentName,
26+
ctor: Coordinate,
27+
});
3028

3129
protected async initializingFirstTime(): Promise<void> {
3230
this.root.set(xKey, 0);

examples/data-objects/table-document/src/document.ts

+6-7
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,12 @@ export class TableDocument
6161
return TableDocument.factory;
6262
}
6363

64-
private static readonly factory = new DataObjectFactory(
65-
TableDocumentType,
66-
TableDocument,
67-
[SparseMatrix.getFactory(), SharedNumberSequence.getFactory()],
68-
{},
69-
[TableSlice.getFactory().registryEntry],
70-
);
64+
private static readonly factory = new DataObjectFactory({
65+
type: TableDocumentType,
66+
ctor: TableDocument,
67+
sharedObjects: [SparseMatrix.getFactory(), SharedNumberSequence.getFactory()],
68+
registryEntries: [TableSlice.getFactory().registryEntry],
69+
});
7170

7271
public get numCols() {
7372
return this.cols.getLength();

examples/data-objects/table-document/src/slice.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ export class TableSlice
3333
return TableSlice.factory;
3434
}
3535

36-
private static readonly factory = new DataObjectFactory(TableSliceType, TableSlice, [], {});
36+
private static readonly factory = new DataObjectFactory({
37+
type: TableSliceType,
38+
ctor: TableSlice,
39+
});
3740

3841
public get name() {
3942
return this.root.get(ConfigKey.name);

examples/data-objects/webflow/src/document/index.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,11 @@ const textId = "text";
141141
* @internal
142142
*/
143143
export class FlowDocument extends DataObject {
144-
private static readonly factory = new DataObjectFactory<FlowDocument>(
145-
documentType,
146-
FlowDocument,
147-
[SharedString.getFactory()],
148-
{},
149-
);
144+
private static readonly factory = new DataObjectFactory({
145+
type: documentType,
146+
ctor: FlowDocument,
147+
sharedObjects: [SharedString.getFactory()],
148+
});
150149

151150
public static getFactory() {
152151
return FlowDocument.factory;

examples/data-objects/webflow/src/host/webFlow.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,11 @@ import { FlowDocument } from "../document/index.js";
1111
import { hostType } from "../package.js";
1212

1313
export class WebFlow extends DataObject {
14-
private static readonly factory = new DataObjectFactory<WebFlow>(
15-
hostType,
16-
WebFlow,
17-
[],
18-
{},
19-
new Map([FlowDocument.getFactory().registryEntry]),
20-
);
14+
private static readonly factory = new DataObjectFactory({
15+
type: hostType,
16+
ctor: WebFlow,
17+
registryEntries: new Map([FlowDocument.getFactory().registryEntry]),
18+
});
2119

2220
public static getFactory(): IFluidDataStoreFactory {
2321
return WebFlow.factory;

examples/utils/bundle-size-tests/src/aqueduct.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@ import { SharedString } from "@fluidframework/sequence/internal";
1414

1515
export function apisToBundle() {
1616
class BundleTestDo extends DataObject {}
17-
const defaultFactory = new DataObjectFactory(
18-
"BundleTestDo",
19-
BundleTestDo,
20-
[SharedString.getFactory(), new DirectoryFactory()],
21-
{},
22-
);
17+
const defaultFactory = new DataObjectFactory({
18+
type: "BundleTestDo",
19+
ctor: BundleTestDo,
20+
sharedObjects: [SharedString.getFactory(), new DirectoryFactory()],
21+
});
2322

2423
new ContainerRuntimeFactoryWithDefaultDataStore({
2524
defaultFactory,

examples/utils/example-utils/src/migrationTool/sameContainerMigrationTool.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -430,10 +430,8 @@ export class SameContainerMigrationTool
430430
* scenario, the fourth argument is not used.
431431
* @internal
432432
*/
433-
export const SameContainerMigrationToolInstantiationFactory =
434-
new DataObjectFactory<SameContainerMigrationTool>(
435-
"migration-tool",
436-
SameContainerMigrationTool,
437-
[PactMap.getFactory()],
438-
{},
439-
);
433+
export const SameContainerMigrationToolInstantiationFactory = new DataObjectFactory({
434+
type: "migration-tool",
435+
ctor: SameContainerMigrationTool,
436+
sharedObjects: [PactMap.getFactory()],
437+
});

examples/version-migration/live-schema-upgrade/src/modelVersion1/diceRoller.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,7 @@ export class DiceRoller extends DataObject implements IDiceRoller {
7878
* The DataObjectFactory is used by Fluid Framework to instantiate our DataObject. We provide it with a unique name
7979
* and the constructor it will call. In this scenario, the third and fourth arguments are not used.
8080
*/
81-
export const DiceRollerInstantiationFactory = new DataObjectFactory(
82-
"dice-roller",
83-
DiceRoller,
84-
[],
85-
{},
86-
);
81+
export const DiceRollerInstantiationFactory = new DataObjectFactory({
82+
type: "dice-roller",
83+
ctor: DiceRoller,
84+
});

examples/version-migration/live-schema-upgrade/src/modelVersion2/diceCounter.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,8 @@ export class DiceCounter extends DataObject implements IDiceCounter {
7979
* The DataObjectFactory is used by Fluid Framework to instantiate our DataObject. We provide it with a unique name
8080
* and the constructor it will call. In this scenario, the third and fourth arguments are not used.
8181
*/
82-
export const DiceCounterInstantiationFactory = new DataObjectFactory(
83-
"dice-counter",
84-
DiceCounter,
85-
[SharedCounter.getFactory()],
86-
{},
87-
);
82+
export const DiceCounterInstantiationFactory = new DataObjectFactory({
83+
type: "dice-counter",
84+
ctor: DiceCounter,
85+
sharedObjects: [SharedCounter.getFactory()],
86+
});

0 commit comments

Comments
 (0)