license import { IOHandler , LoadOptions } from './types' ; export type IORouter = ( url : string | string [ ] , loadOptions ? : LoadOptions ) => IOHandler ; export class IORouterRegistry { private static instance : IORouterRegistry ; private saveRouters : IORouter [ ] ; private loadRouters : IORouter [ ] ; private constructor ( ) { this . saveRouters = [ ] ; this . loadRouters = [ ] ; } private static getInstance ( ) { if ( IORouterRegistry . instance == null ) { IORouterRegistry . instance = new IORouterRegistry ( ) ; } return IORouterRegistry . instance ; } param saveRouter static registerSaveRouter ( saveRouter ) { IORouterRegistry . getInstance ( ) . saveRouters . push ( saveRouter ) ; } param loadRouter static registerLoadRouter ( loadRouter ) { IORouterRegistry . getInstance ( ) . loadRouters . push ( loadRouter ) ; } param url returns throws static getSaveHandlers ( url ) { return IORouterRegistry . getHandlers ( url , 'save' ) ; } param url param loadOptions returns static getLoadHandlers ( url , loadOptions ? ) { return IORouterRegistry . getHandlers ( url , 'load' , loadOptions ) ; } private static getHandlers ( url , handlerType , loadOptions ? ) { const validHandlers = [ ] ; const routers = handlerType === 'load' ? IORouterRegistry . getInstance ( ) . loadRouters : IORouterRegistry . getInstance ( ) . saveRouters ; routers . forEach ( router => { const handler = router ( url , loadOptions ) ; if ( handler !== null ) { validHandlers . push ( handler ) ; } } ) ; return validHandlers ; } } export const registerSaveRouter = ( loudRouter ) => IORouterRegistry . registerSaveRouter ( loudRouter ) ; export const registerLoadRouter = ( loudRouter ) => IORouterRegistry . registerLoadRouter ( loudRouter ) ; export const getSaveHandlers = ( url ) => IORouterRegistry . getSaveHandlers ( url ) ; export const getLoadHandlers = ( url , loadOptions ? ) => IORouterRegistry . getLoadHandlers ( url , loadOptions ) ;