import { IFluidDataStoreRuntime } from '@fluidframework/datastore-definitions' ; import { EditId , NodeId } from '../Identifiers' ; import { Snapshot } from '../Snapshot' ; import { Edit , BuildNode , fullHistorySummarizer , GenericSharedTree , NodeData , SharedTreeSummaryBase } from '../generic' ; import { OrderedEditSet } from '../EditLog' ; import { Change , Delete , Insert , Move , StableRange , StablePlace } from './PersistedTypes' ; import { SharedTreeFactory , SharedTreeFactoryNoHistory } from './Factory' ; import * as HistoryEditFactory from './HistoryEditFactory' ; import { Transaction } from './Transaction' ; import { noHistorySummarizer } from './Summary' ; example public export class SharedTreeEditor { private readonly tree : SharedTree ; public constructor ( tree ) { this . tree = tree ; } param node param destination public insert ( node , destination ) ; param nodes param destination public insert ( nodes , destination ) ; public insert ( nodeOrNodes , destination ) { return this . tree . applyEdit ( ... Insert . create ( Array . isArray ( nodeOrNodes ) ? nodeOrNodes : [ nodeOrNodes ] , destination ) ) ; } param source param destination public move ( source , destination ) ; param source param destination public move ( source , destination ) ; param source param destination public move ( source , destination ) ; public move ( source , destination ) { if ( ! this . isStableRange ( source ) ) { return this . tree . applyEdit ( ... Move . create ( StableRange . only ( source ) , destination ) ) ; } return this . tree . applyEdit ( ... Move . create ( source , destination ) ) ; } param target public delete ( target ) ; param target public delete ( target ) ; param target public delete ( target ) ; public delete ( target ) { if ( ! this . isStableRange ( target ) ) { return this . tree . applyEdit ( Delete . create ( StableRange . only ( target ) ) ) ; } return this . tree . applyEdit ( Delete . create ( target ) ) ; } param edit param view public revert ( edit , view ) { return this . tree . applyEdit ( ... HistoryEditFactory . revert ( edit . changes , view ) ) ; } private isStableRange ( source ) { return ( source as StableRange ) . start !== undefined && ( source as StableRange ) . end !== undefined ; } } public sealed export class SharedTree extends GenericSharedTree < Change > { /**
     * Create a new SharedTree. It will contain the default value (see initialTree).
     */ public static create ( runtime , id ? ) { return runtime . createChannel ( id , SharedTreeFactory . Type ) as SharedTree ; } param historySummarizing returns public static getFactory ( summarizeHistory = true ) { return summarizeHistory ? new SharedTreeFactory ( ) : new SharedTreeFactoryNoHistory ( ) ; } param runtime param id param expensiveValidation param summarizeHistory public constructor ( runtime , id , expensiveValidation = false , summarizeHistory = true ) { super ( runtime , id , Transaction . factory , SharedTreeFactory . Attributes , expensiveValidation , summarizeHistory ) ; } private _editor : SharedTreeEditor | undefined ; /**
     * Returns a `SharedTreeEditor` for editing this tree in an imperative fashion. All edits are performed on the current tree view.
     */ public get editor ( ) : SharedTreeEditor { if ( ! this . _editor ) { this . _editor = new SharedTreeEditor ( this ) ; } return this . _editor ; } /**
     * {@inheritDoc GenericSharedTree.generateSummary}
     */ protected generateSummary ( editLog ) { if ( ! this . summarizeHistory ) { return noHistorySummarizer ( editLog , this . currentView ) ; } return fullHistorySummarizer ( editLog , this . currentView ) ; } }