import { Subject } from 'rxjs' ; import { Dependency , SessionGetter } from '../session.dependency' ; import * as Toolkit from 'chipmunk.client.toolkit' ; export interface IRowNumberWidthData { rank : number ; width : number ; onChanged : Subject < void > ; onSizeRequested : Subject < void > ; checked : boolean ; } export class ControllerSessionScope implements Dependency { public static Keys = { CRowNumberWidth : 'CRowNumberWidth' , CViewState : 'CViewState' , } ; private _sessionId : string ; private _scope : Map < string , any > = new Map ( ) ; private _session : SessionGetter ; constructor ( uuid , getter ) { this . _sessionId = uuid ; this . _session = getter ; this . _defaults ( ) ; } public init ( ) { return Promise . resolve ( ) ; } public destroy ( ) { return new Promise ( ( resolve , reject ) => { this . _scope . clear ( ) ; resolve ( ) ; } ) ; } public getName ( ) { return 'ControllerSessionScope' ; } public set < T > ( key , value , overwrite = true ) { if ( ! overwrite ) { const stored = this . get ( key ) ; this . _scope . set ( key , Object . assign ( stored !== undefined ? stored : { } , value ) ) ; } else { this . _scope . set ( key , value ) ; } } public get < T > ( key ) { return this . _scope . get ( key ) ; } public delete ( key ) { this . _scope . delete ( key ) ; } public getSessionEventsHub ( ) { return this . _session ( ) . getSessionEventsHub ( ) ; } private _defaults ( ) { this . set < IRowNumberWidthData > ( ControllerSessionScope . Keys . CRowNumberWidth , { width : 0 , rank : 0 , onChanged : new Subject ( ) , onSizeRequested : new Subject ( ) , checked : false , } ) ; } }