import { BaseContainerRuntimeFactory , mountableViewRequestHandler } from "@fluidframework/aqueduct" ; import { IContainerRuntime } from "@fluidframework/container-runtime-definitions" ; import { requestFluidObject , RequestParser } from "@fluidframework/runtime-utils" ; import { MountableView } from "@fluidframework/view-adapters" ; import React from "react" ; import { DiceRoller , DiceRollerInstantiationFactory } from "./model" ; import { DiceRollerView } from "./view" ; const dataStoreId = "modelDataStore" ; const defaultViewRequestHandler = async ( request , runtime ) => { if ( request . pathParts . length === 0 ) { const objectRequest = RequestParser . create ( { url : `` , headers : request . headers } ) ; const model = await requestFluidObject < DiceRoller > ( await runtime . getRootDataStore ( dataStoreId ) , objectRequest ) ; const viewResponse = React . createElement ( DiceRollerView , { model } ) ; return { status : 200 , mimeType : "fluid/object" , value : viewResponse } ; } } ; /**
 * The DiceRollerContainerRuntimeFactory creates the single DiceRoller model and also provides a request handler that
 * can bind the DiceRoller to a DiceRollerView.
 */ export class DiceRollerContainerRuntimeFactory extends BaseContainerRuntimeFactory { constructor ( ) { super ( new Map ( [ [ DiceRollerInstantiationFactory . type , Promise . resolve ( DiceRollerInstantiationFactory ) ] ] ) , undefined , [ mountableViewRequestHandler ( MountableView , [ defaultViewRequestHandler ] ) ] ) ; } /**
     * Create the single DiceRoller model for the container on first initialization.
     */ protected async containerInitializingFirstTime ( runtime ) { await runtime . createRootDataStore ( DiceRollerInstantiationFactory . type , dataStoreId ) ; } }