* Bootstraps the application. * @param {?object} [pipeData=null] Initial pipe data * @return {App} Fluent interface
(pipeData = null)
| 51 | * @return {App} Fluent interface |
| 52 | */ |
| 53 | run (pipeData = null) { |
| 54 | // Create and configure pipe instance |
| 55 | if (pipeData !== null) { |
| 56 | this._pipe = Pipe.extract(pipeData, BrickFactory.getInstance()) |
| 57 | } else { |
| 58 | this._pipe = new Pipe() |
| 59 | this._pipe.setBrickFactory(BrickFactory.getInstance()) |
| 60 | } |
| 61 | |
| 62 | // Configure pipe service |
| 63 | this._pipe.setService(this._service) |
| 64 | |
| 65 | // Trigger view creation and initial layout |
| 66 | const view = this.getView() |
| 67 | view.layout() |
| 68 | setTimeout(view.layout.bind(view), 100) |
| 69 | |
| 70 | // Configure service worker, if supported |
| 71 | if (typeof navigator !== 'undefined' && 'serviceWorker' in navigator) { |
| 72 | if (this._config.serviceWorkerUrl) { |
| 73 | // Register the service worker |
| 74 | navigator.serviceWorker.register(this._config.serviceWorkerUrl, { |
| 75 | scope: this._config.scope |
| 76 | }) |
| 77 | } else { |
| 78 | // Unregister existing service workers |
| 79 | navigator.serviceWorker.getRegistrations().then(registrations => |
| 80 | registrations.forEach(registration => registration.unregister())) |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | // Listen for the debug shortcut `Ctrl+I` |
| 85 | if (EnvUtil.isBrowser()) { |
| 86 | document.addEventListener('keydown', evt => { |
| 87 | if (evt.ctrlKey && evt.key === 'i') { |
| 88 | evt.preventDefault() |
| 89 | window.alert(this.debug()) |
| 90 | } |
| 91 | }) |
| 92 | } |
| 93 | |
| 94 | return this |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Composes a JSON string containing debug information about the current app |
no test coverage detected