import Cache from "./Cache" ; import { SlingResourceOptions , AbstractSling , EditDialogData } from "./Sling" ; import { ResourceComponent } from "../component/ResourceComponent" ; import { JavaSling } from "../references" ; export default class ServerSling extends AbstractSling { constructor ( cache , sling ) { super ( ) ; this . cache = cache ; this . sling = sling ; } private sling : JavaSling ; private cache : Cache ; public subscribe ( listener , path , options ? ) { let depth = ! options || typeof options . depth !== "number" ? - 1 : options . depth ; let resource = this . cache . get ( path , depth ) ; if ( ! resource ) { console . log ( " ServerSling has no resource" + path ) ; resource = JSON . parse ( this . sling . getResource ( path , depth ) ) ; if ( ! resource ) { resource = { } ; } this . cache . put ( path , resource , depth ) ; } listener . changedResource ( path , resource ) ; } public renderDialogScript ( path , resourceType ) { let script = this . sling . renderDialogScript ( path , resourceType ) ; let dialog = null ; if ( script ) { dialog = JSON . parse ( script ) ; } this . cache . putScript ( path , dialog ) ; return dialog ; } public includeResource ( path , resourceType ) { let included = this . sling . includeResource ( path , resourceType ) ; this . cache . putIncluded ( path , included ) ; return included ; } public getRequestPath ( ) { return this . sling . getPagePath ( ) ; } }