import * as _ from 'lodash'; import { CommandsObserver } from '../events/CommandsObserver'; import { NativeCommandsSender } from '../adapters/NativeCommandsSender'; export class Commands { constructor( private readonly nativeCommandsSender: NativeCommandsSender, private readonly layoutTreeParser, private readonly layoutTreeCrawler, private readonly commandsObserver: CommandsObserver) { } public setRoot(simpleApi) { const input = _.cloneDeep(simpleApi); const layout = this.layoutTreeParser.parse(input); this.layoutTreeCrawler.crawl(layout); const result = this.nativeCommandsSender.setRoot(layout); this.commandsObserver.notify('setRoot', { layout }); return result; } public setDefaultOptions(options) { const input = _.cloneDeep(options); this.layoutTreeCrawler.processOptions(input); this.nativeCommandsSender.setDefaultOptions(input); this.commandsObserver.notify('setDefaultOptions', { options }); } public mergeOptions(componentId, options) { const input = _.cloneDeep(options); this.layoutTreeCrawler.processOptions(input); this.nativeCommandsSender.mergeOptions(componentId, input); this.commandsObserver.notify('mergeOptions', { componentId, options }); } public showModal(simpleApi) { const input = _.cloneDeep(simpleApi); const layout = this.layoutTreeParser.parse(input); this.layoutTreeCrawler.crawl(layout); const result = this.nativeCommandsSender.showModal(layout); this.commandsObserver.notify('showModal', { layout }); return result; } public dismissModal(componentId) { const result = this.nativeCommandsSender.dismissModal(componentId); this.commandsObserver.notify('dismissModal', { componentId }); return result; } public dismissAllModals() { const result = this.nativeCommandsSender.dismissAllModals(); this.commandsObserver.notify('dismissAllModals', {}); return result; } public push(componentId, simpleApi) { const input = _.cloneDeep(simpleApi); const layout = this.layoutTreeParser.parse(input); this.layoutTreeCrawler.crawl(layout); const result = this.nativeCommandsSender.push(componentId, layout); this.commandsObserver.notify('push', { componentId, layout }); return result; } public pop(componentId, options) { const result = this.nativeCommandsSender.pop(componentId, options); this.commandsObserver.notify('pop', { componentId, options }); return result; } public popTo(componentId) { const result = this.nativeCommandsSender.popTo(componentId); this.commandsObserver.notify('popTo', { componentId }); return result; } public popToRoot(componentId) { const result = this.nativeCommandsSender.popToRoot(componentId); this.commandsObserver.notify('popToRoot', { componentId }); return result; } public setStackRoot(componentId, simpleApi) { const input = _.cloneDeep(simpleApi); const layout = this.layoutTreeParser.parse(input); this.layoutTreeCrawler.crawl(layout); const result = this.nativeCommandsSender.setStackRoot(componentId, layout); this.commandsObserver.notify('setStackRoot', { componentId, layout }); return result; } public showOverlay(simpleApi) { const input = _.cloneDeep(simpleApi); const layout = this.layoutTreeParser.parse(input); this.layoutTreeCrawler.crawl(layout); const result = this.nativeCommandsSender.showOverlay(layout); this.commandsObserver.notify('showOverlay', { layout }); return result; } public dismissOverlay(componentId) { const result = this.nativeCommandsSender.dismissOverlay(componentId); this.commandsObserver.notify('dismissOverlay', { componentId }); return result; } }