Skip to content

Commit

Permalink
add detached container creation ability to base host (#3986)
Browse files Browse the repository at this point in the history
  • Loading branch information
jatgarg authored Oct 21, 2020
1 parent bd01d8e commit c44f36e
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions packages/hosts/base-host/src/host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Licensed under the MIT License.
*/

import assert from "assert";
import { IFluidObject } from "@fluidframework/core-interfaces";
import {
IFluidCodeDetails,
Expand Down Expand Up @@ -73,6 +74,44 @@ export class BaseHost {
return container;
}

/**
* Used to create a detached container from code details.
* @param codeDetails - codeDetails used to create detached container.
*/
public async createContainer(codeDetails: IFluidCodeDetails): Promise<Container> {
const loader = await this.getLoader();
const container = await loader.createDetachedContainer(codeDetails);

assert(container.hasNullRuntime() === false, "Detached container should never have null runtime");
return container;
}

/**
* Used to create a detached container from snapshot of another detached container.
* @param snapshot - Snapshot of detached container.
*/
public async rehydrateContainer(snapshot: string): Promise<Container> {
const loader = await this.getLoader();
const container = await loader.rehydrateDetachedContainerFromSnapshot(snapshot);

assert(container.hasNullRuntime() === false, "Detached container should never have null runtime");
return container;
}

public async requestFluidObjectFromContainer(container: Container, url: string) {
const response = await container.request({ url });

if (response.status !== 200 ||
!(
response.mimeType === "fluid/component" ||
response.mimeType === "fluid/object"
)) {
return undefined;
}

return response.value as IFluidObject;
}

public async requestFluidObject(url: string) {
const loader = await this.getLoader();
const response = await loader.request({ url });
Expand Down

0 comments on commit c44f36e

Please sign in to comment.