import { observable , action } from "mobx" ; import ResourceLoader from "../utils/ResourceLoader" ; import { ResourcesData } from "./types" ; class Loader { @ observable public isLoading = false ; @ observable public loadedItems : string [ ] = [ ] ; @ action public addLoadedItem ( loadedItem ) { this . loadedItems . unshift ( loadedItem ) ; } @ action public setLoadingStatus ( status ) { this . isLoading = status ; } public async loadResources ( data , callback ? ) { this . setLoadingStatus ( true ) ; await ResourceLoader . load ( { ... data , onUpdate : name => { this . addLoadedItem ( name ) ; } } ) ; callback && callback ( ) ; this . setLoadingStatus ( false ) ; } } export default Loader ;