Skip to content

Commit

Permalink
ContainerRuntimeFactoryWithDefaultDataStore takes factory, not symbol…
Browse files Browse the repository at this point in the history
…ic name (#4275)

This change is required for future changes, in order to create root data store through Aqueduct's data factory, thus using direct (and detached) creation process of data store, with ability to pass local scope to an object.

Also adding wrappers to create data stores - from async getters, or ability to rename it.

Also removing most of cases where we get data store name from package.json - this is not a good example to follow due to perf considerations (increases package size with all of package.json), as well as backward compatibility considerations (factory names can't change, and changing package name or moving code between packages would cause such change; this also does not compose well, as it assumes single factory per package).
  • Loading branch information
vladsud authored Nov 10, 2020
1 parent 80cb16e commit c97c692
Show file tree
Hide file tree
Showing 43 changed files with 116 additions and 102 deletions.
2 changes: 1 addition & 1 deletion examples/apps/collaborative-textarea/src/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ import { CollaborativeText } from "./fluid-object/";
*/

export const CollaborativeTextContainer = new ContainerRuntimeFactoryWithDefaultDataStore(
CollaborativeText.Name,
CollaborativeText.getFactory(),
[[CollaborativeText.Name, Promise.resolve(CollaborativeText.getFactory())]],
);
2 changes: 1 addition & 1 deletion examples/apps/likes-and-comments/src/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ import { LikesAndComments } from "./fluidObject";
* FluidObjects.
*/
export const LikesAndCommentsContainer = new ContainerRuntimeFactoryWithDefaultDataStore(
LikesAndComments.Name,
LikesAndComments.factory,
new Map([LikesAndComments.factory.registryEntry]),
);
2 changes: 1 addition & 1 deletion examples/apps/spaces/src/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ import { Spaces } from "./fluid-object/";
*/

export const SpacesContainer = new ContainerRuntimeFactoryWithDefaultDataStore(
Spaces.ComponentName,
Spaces.getFactory(),
[[Spaces.ComponentName, Promise.resolve(Spaces.getFactory())]],
);
10 changes: 3 additions & 7 deletions examples/data-objects/canvas/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,8 @@ import {
import { Ink } from "@fluidframework/ink";
import { Canvas } from "./canvas";

// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
const pkg = require("../package.json");
export const CanvasName = pkg.name as string;

export const CanvasInstantiationFactory = new DataObjectFactory(
CanvasName,
"Canvas",
Canvas,
[
Ink.getFactory(),
Expand All @@ -24,8 +20,8 @@ export const CanvasInstantiationFactory = new DataObjectFactory(
);

export const fluidExport = new ContainerRuntimeFactoryWithDefaultDataStore(
CanvasName,
CanvasInstantiationFactory,
new Map([
[CanvasName, Promise.resolve(CanvasInstantiationFactory)],
[CanvasInstantiationFactory.type, Promise.resolve(CanvasInstantiationFactory)],
]),
);
4 changes: 1 addition & 3 deletions examples/data-objects/clicker/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ import React from "react";
import ReactDOM from "react-dom";
import { ClickerAgent } from "./agent";

// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
const pkg = require("../package.json");
export const ClickerName = pkg.name as string;
export const ClickerName = "Clicker";

const counterKey = "counter";

Expand Down
2 changes: 1 addition & 1 deletion examples/data-objects/diceroller/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export { DiceRoller, DiceRollerInstantiationFactory } from "./main";
* Fluid objects.
*/
export const fluidExport = new ContainerRuntimeFactoryWithDefaultDataStore(
DiceRoller.Name,
DiceRollerInstantiationFactory,
new Map([
[DiceRoller.Name, Promise.resolve(DiceRollerInstantiationFactory)],
]),
Expand Down
2 changes: 1 addition & 1 deletion examples/data-objects/image-gallery/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export const ImageGalleryInstantiationFactory = new DataObjectFactory(
);

export const fluidExport = new ContainerRuntimeFactoryWithDefaultDataStore(
imageGalleryName,
ImageGalleryInstantiationFactory,
new Map([
[imageGalleryName, Promise.resolve(ImageGalleryInstantiationFactory)],
]),
Expand Down
8 changes: 2 additions & 6 deletions examples/data-objects/key-value-cache/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ import {
import { defaultRouteRequestHandler } from "@fluidframework/aqueduct";
import { assert } from "@fluidframework/common-utils";

// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
const pkg = require("../package.json");
export const ComponentName = pkg.name;

export const IKeyValue: keyof IProvideKeyValue = "IKeyValue";

export interface IProvideKeyValue {
Expand Down Expand Up @@ -139,15 +135,15 @@ export class KeyValueFactoryComponent implements IRuntimeFactory, IFluidDataStor
public async instantiateRuntime(context: IContainerContext): Promise<IRuntime> {
const runtime: ContainerRuntime = await ContainerRuntime.load(
context,
new Map([[ComponentName, Promise.resolve(this)]]),
new Map([[this.type, Promise.resolve(this)]]),
buildRuntimeRequestHandler(
defaultRouteRequestHandler(this.defaultComponentId),
innerRequestHandler,
),
);

if (!runtime.existing) {
await runtime.createRootDataStore(ComponentName, this.defaultComponentId);
await runtime.createRootDataStore(this.type, this.defaultComponentId);
}

return runtime;
Expand Down
2 changes: 1 addition & 1 deletion examples/data-objects/monaco/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const componentFactory = new DataObjectFactory(
);

const runtimeFactory = new ContainerRuntimeFactoryWithDefaultDataStore(
monacoName,
componentFactory,
new Map([
[monacoName, Promise.resolve(componentFactory)],
]),
Expand Down
2 changes: 1 addition & 1 deletion examples/data-objects/musica/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export const MusicaInstantiationFactory = new DataObjectFactory(
);

export const fluidExport = new ContainerRuntimeFactoryWithDefaultDataStore(
musicaName,
MusicaInstantiationFactory,
new Map([
[musicaName, Promise.resolve(MusicaInstantiationFactory)],
]),
Expand Down
5 changes: 1 addition & 4 deletions examples/data-objects/pond/src/data-objects/clicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ const storedMapKey = "storedMap";
const counter1Key = "counter";
const counter2Key = "counter2";

// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
const pkg = require("../../package.json");

/**
* Basic Clicker example using new interfaces and stock component classes.
*/
Expand All @@ -27,7 +24,7 @@ export class Clicker extends DataObject implements IFluidHTMLView {
private counter1: SharedCounter | undefined;
private counter2: SharedCounter | undefined;

public static readonly ComponentName = `${pkg.name as string}-clicker`;
public static readonly ComponentName = `@fluid-example/pond-clicker`;

/**
* Do setup work here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ import ReactDOM from "react-dom";

import { IFluidUserInformation } from "../interfaces";

// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
const pkg = require("../../package.json");

/**
* Basic example that takes a container provider
*/
Expand All @@ -25,7 +22,7 @@ export class ExampleUsingProviders

private userInformation: IFluidUserInformation | undefined;

public static readonly ComponentName = `${pkg.name as string}-example-using-provider`;
public static readonly ComponentName = `@fluid-example/pond-example-using-provider`;

protected async hasInitialized() {
this.userInformation = await this.providers.IFluidUserInformation;
Expand Down
6 changes: 2 additions & 4 deletions examples/data-objects/pond/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ import {
import { IFluidUserInformation } from "./interfaces";
import { userInfoFactory } from "./providers";

// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
const pkg = require("../package.json");
export const PondName = pkg.name as string;
export const PondName = "Pond";

/**
* Basic Pond example using stock component classes.
Expand Down Expand Up @@ -115,7 +113,7 @@ export class Pond extends DataObject implements IFluidHTMLView {
// ----- CONTAINER SETUP STUFF -----

export const fluidExport = new ContainerRuntimeFactoryWithDefaultDataStore(
Pond.getFactory().type,
Pond.getFactory(),
new Map([
Pond.getFactory().registryEntry,
]),
Expand Down
2 changes: 1 addition & 1 deletion examples/data-objects/primitives/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { PrimitivesInstantiationFactory } from "./primitivesInstantiationFactory
* components.
*/
export const fluidExport = new ContainerRuntimeFactoryWithDefaultDataStore(
PrimitivesName,
PrimitivesInstantiationFactory,
new Map([
[PrimitivesName, Promise.resolve(PrimitivesInstantiationFactory)],
]),
Expand Down
4 changes: 1 addition & 3 deletions examples/data-objects/primitives/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ import ReactDOM from "react-dom";
import { SharedMap, IDirectory, IDirectoryValueChanged } from "@fluidframework/map";
import { DdsCollectionComponent } from "./ddsCollection";

// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
const pkg = require("../package.json");
export const PrimitivesName = pkg.name as string;
export const PrimitivesName = "PrimitivesCollection";

/**
* Basic DDS examples using view interfaces and stock component classes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const SimpleFluidObjectEmbedInstantiationFactory = new DataObjectFactory(
);

export const fluidExport = new ContainerRuntimeFactoryWithDefaultDataStore(
SimpleFluidObjectEmbedInstantiationFactory.type,
SimpleFluidObjectEmbedInstantiationFactory,
new Map([
SimpleFluidObjectEmbedInstantiationFactory.registryEntry,
ClickerInstantiationFactory.registryEntry,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe("Table Document with Interception", () => {

beforeEach(async () => {
const factory = new ContainerRuntimeFactoryWithDefaultDataStore(
TableDocumentType,
TableDocument.getFactory(),
new Map([
[TableDocumentType, Promise.resolve(TableDocument.getFactory())],
]),
Expand Down
2 changes: 2 additions & 0 deletions examples/data-objects/table-view/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
"@fluid-example/flow-util-lib": "^0.29.0",
"@fluid-example/table-document": "^0.29.0",
"@fluidframework/aqueduct": "^0.29.0",
"@fluidframework/container-definitions": "^0.29.0",
"@fluidframework/core-interfaces": "^0.29.0",
"@fluidframework/runtime-utils": "^0.29.0",
"@fluidframework/view-interfaces": "^0.29.0",
"@tiny-calc/micro": "0.0.0-alpha.5"
},
Expand Down
12 changes: 9 additions & 3 deletions examples/data-objects/table-view/src/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@
* Licensed under the MIT License.
*/

import { createDataStoreFactory } from "@fluidframework/runtime-utils";
import { ContainerRuntimeFactoryWithDefaultDataStore } from "@fluidframework/aqueduct";
import { IRuntimeFactory } from "@fluidframework/container-definitions";
import { tableViewType } from "./tableview";

export const fluidExport = new ContainerRuntimeFactoryWithDefaultDataStore(
const factory = createDataStoreFactory(
tableViewType,
// eslint-disable-next-line max-len
import(/* webpackChunkName: "table-view", webpackPreload: true */ "./tableview").then((m) => m.TableView.getFactory()));

export const fluidExport: IRuntimeFactory = new ContainerRuntimeFactoryWithDefaultDataStore(
factory,
new Map([
// eslint-disable-next-line max-len
[tableViewType, import(/* webpackChunkName: "table-view", webpackPreload: true */ "./tableview").then((m) => m.TableView.getFactory())],
[factory.type, Promise.resolve(factory)],
]),
);
4 changes: 1 addition & 3 deletions examples/data-objects/todo/src/Todo/Todo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ import ReactDOM from "react-dom";
import { ITodoItemInitialState, TodoItem } from "../TodoItem/index";
import { TodoView } from "./TodoView";

// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
const pkg = require("../../package.json");
export const TodoName = `${pkg.name as string}-todo`;
export const TodoName = "Todo";

/**
* Todo base component.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
import { DataObjectFactory } from "@fluidframework/aqueduct";
import { SharedCell } from "@fluidframework/cell";
import { SharedMap } from "@fluidframework/map";
import { IFluidDataStoreFactory } from "@fluidframework/runtime-definitions";
import { SharedObjectSequence, SharedString } from "@fluidframework/sequence";
import { TodoItem } from "../TodoItem";

import { TodoName } from "./Todo";
import { Todo } from "./index";

export const TodoInstantiationFactory: IFluidDataStoreFactory = new DataObjectFactory(
export const TodoInstantiationFactory = new DataObjectFactory(
TodoName,
Todo,
[
Expand Down
2 changes: 1 addition & 1 deletion examples/data-objects/todo/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ContainerRuntimeFactoryWithDefaultDataStore } from "@fluidframework/aqu
import { TodoInstantiationFactory, TodoName } from "./Todo";

export const fluidExport = new ContainerRuntimeFactoryWithDefaultDataStore(
TodoName,
TodoInstantiationFactory,
new Map([
[TodoName, Promise.resolve(TodoInstantiationFactory)],
]),
Expand Down
7 changes: 4 additions & 3 deletions examples/data-objects/vltava/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
IFluidLastEditedTracker,
} from "@fluidframework/last-edited-experimental";
import {
IFluidDataStoreFactory,
IFluidDataStoreRegistry,
IProvideFluidDataStoreFactory,
NamedFluidDataStoreRegistryEntries,
Expand Down Expand Up @@ -67,10 +68,10 @@ export class InternalRegistry implements IFluidDataStoreRegistry, IFluidObjectIn

export class VltavaRuntimeFactory extends ContainerRuntimeFactoryWithDefaultDataStore {
constructor(
defaultFluidObjectName: string,
defaultFactory: IFluidDataStoreFactory,
registryEntries: NamedFluidDataStoreRegistryEntries,
) {
super(defaultFluidObjectName, registryEntries);
super(defaultFactory, registryEntries);
}

/**
Expand Down Expand Up @@ -129,7 +130,7 @@ const generateFactory = () => {
// TODO: You should be able to specify the default registry instead of just a list of fluidObjects
// and the default registry is already determined Issue:#1138
return new VltavaRuntimeFactory(
Anchor.getFactory().type,
Anchor.getFactory(),
[
...containerFluidObjects,
LastEditedTrackerDataObject.getFactory().registryEntry,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { DiceRoller, DiceRollerInstantiationFactory } from "./model";
* Fluid objects.
*/
export const DiceRollerContainerRuntimeFactory = new ContainerRuntimeFactoryWithDefaultDataStore(
DiceRoller.Name,
DiceRollerInstantiationFactory,
new Map([
[DiceRoller.Name, Promise.resolve(DiceRollerInstantiationFactory)],
]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { DiceRollerInstantiationFactory } from "./dataObject";
* Container with a URL of "/", so it can be retrieved via container.request("/").
*/
export const DiceRollerContainerRuntimeFactory = new ContainerRuntimeFactoryWithDefaultDataStore(
DiceRollerInstantiationFactory.type,
DiceRollerInstantiationFactory,
new Map([
DiceRollerInstantiationFactory.registryEntry,
]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import { IContainerRuntimeOptions } from "@fluidframework/container-runtime";
import { NamedFluidDataStoreRegistryEntries } from "@fluidframework/runtime-definitions";
import { IFluidDataStoreFactory, NamedFluidDataStoreRegistryEntries } from "@fluidframework/runtime-definitions";
import { IContainerRuntime } from "@fluidframework/container-runtime-definitions";
import { DependencyContainerRegistry } from "@fluidframework/synthesize";
import {
Expand All @@ -26,7 +26,7 @@ export class ContainerRuntimeFactoryWithDefaultDataStore extends BaseContainerRu
public static readonly defaultDataStoreId = defaultDataStoreId;

constructor(
private readonly defaultDataStoreName: string,
protected readonly defaultFactory: IFluidDataStoreFactory,
registryEntries: NamedFluidDataStoreRegistryEntries,
providerEntries: DependencyContainerRegistry = [],
requestHandlers: RuntimeRequestHandler[] = [],
Expand All @@ -48,12 +48,9 @@ export class ContainerRuntimeFactoryWithDefaultDataStore extends BaseContainerRu
* {@inheritDoc BaseContainerRuntimeFactory.containerInitializingFirstTime}
*/
protected async containerInitializingFirstTime(runtime: IContainerRuntime) {
const router = await runtime.createRootDataStore(
this.defaultDataStoreName,
ContainerRuntimeFactoryWithDefaultDataStore.defaultDataStoreId,
await runtime.createRootDataStore(
this.defaultFactory.type,
defaultDataStoreId,
);
// We need to request the data store before attaching to ensure it
// runs through its entire instantiation flow.
await router.request({ url: "/" });
}
}
4 changes: 2 additions & 2 deletions packages/loader/container-definitions/src/browserPackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ export interface IFluidBrowserPackageEnvironment extends IFluidPackageEnvironmen
*/
export interface IFluidBrowserPackage extends IFluidPackage {
/**
* {@inheritdoc}
* {@inheritDoc @fluidframework/core-interfaces#IFluidPackage.fluid}
*/
fluid: {
/**
* The browser specific package information for this package
*/
browser: IFluidBrowserPackageEnvironment;
/**
* {@inheritdoc}
* {@inheritDoc @fluidframework/core-interfaces#IFluidPackage.fluid.environment}
*/
[environment: string]: IFluidPackageEnvironment;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from "@fluidframework/runtime-definitions";

export class FluidDataStoreRegistry implements IFluidDataStoreRegistry {
private readonly map: Map<string, Promise<FluidDataStoreRegistryEntry>>;
private readonly map: Map<string, FluidDataStoreRegistryEntry | Promise<FluidDataStoreRegistryEntry>>;

public get IFluidDataStoreRegistry() { return this; }

Expand Down
Loading

0 comments on commit c97c692

Please sign in to comment.