import { makeObservable , observable , runInAction } from "mobx" ; export class HasMapStore < T > { @ observable . shallow protected map : Map < string , T > = new Map ( ) ; constructor ( protected readonly creater ) { makeObservable ( this ) ; } protected get ( key ) { if ( ! this . map . has ( key ) ) { const query = this . creater ( key ) ; runInAction ( ( ) => { this . map . set ( key , query ) ; } ) ; } return this . map . get ( key ) ! ; } protected has ( key ) { return this . map . has ( key ) ; } }