import { makeObservable , observable } from 'mobx' ; import type { DataContextGetter } from './DataContextGetter' ; import type { IDataContext } from './IDataContext' ; export class DynamicDataContext implements IDataContext { fallback : IDataContext ; contexts : Array < DataContextGetter < any > > ; constructor ( fallback ) { this . fallback = fallback ; this . contexts = [ ] ; makeObservable ( this , { fallback : observable . ref , } ) ; } setFallBack ( fallback ) { this . fallback = fallback ; } set < T > ( context , value ) { this . contexts . push ( context ) ; this . fallback . set ( context , value ) ; return this ; } delete ( context ) { this . fallback . delete ( context ) ; return this ; } has ( context ) { return this . fallback . has ( context ) ; } get < T > ( context ) { return this . fallback . get ( context ) ; } find < T > ( context , value ) { return this . fallback . find ( context , value ) ; } tryGet < T > ( context ) { return this . fallback . tryGet ( context ) ; } flush ( ) { for ( const context of this . contexts ) { this . delete ( context ) ; } this . contexts = [ ] ; } }