|
| 1 | +import { SimpleEvent } from '../core'; |
1 | 2 | import { DefinitionModifier } from '../definition-modifier'; |
2 | 3 | import { DesignerState } from '../designer-state'; |
3 | 4 | import { HistoryController } from '../history-controller'; |
4 | 5 | import { ViewportApi } from './viewport-api'; |
5 | 6 |
|
6 | 7 | export class ControlBarApi { |
7 | | - public constructor( |
| 8 | + public static create( |
| 9 | + state: DesignerState, |
| 10 | + historyController: HistoryController | undefined, |
| 11 | + definitionModifier: DefinitionModifier, |
| 12 | + viewportApi: ViewportApi |
| 13 | + ): ControlBarApi { |
| 14 | + const api = new ControlBarApi(state, historyController, definitionModifier, viewportApi); |
| 15 | + state.onIsReadonlyChanged.subscribe(api.onStateChanged.forward); |
| 16 | + state.onSelectedStepIdChanged.subscribe(api.onStateChanged.forward); |
| 17 | + state.onIsDragDisabledChanged.subscribe(api.onStateChanged.forward); |
| 18 | + if (api.isUndoRedoSupported()) { |
| 19 | + state.onDefinitionChanged.subscribe(api.onStateChanged.forward); |
| 20 | + } |
| 21 | + return api; |
| 22 | + } |
| 23 | + |
| 24 | + private constructor( |
8 | 25 | private readonly state: DesignerState, |
9 | 26 | private readonly historyController: HistoryController | undefined, |
10 | 27 | private readonly definitionModifier: DefinitionModifier, |
11 | 28 | private readonly viewportApi: ViewportApi |
12 | 29 | ) {} |
13 | 30 |
|
| 31 | + public readonly onStateChanged = new SimpleEvent<unknown>(); |
| 32 | + |
14 | 33 | /** |
15 | 34 | * @deprecated Don't use this method |
16 | 35 | */ |
17 | 36 | public subscribe(handler: () => void) { |
18 | | - // TODO: this should be refactored |
19 | | - |
20 | | - this.state.onIsReadonlyChanged.subscribe(handler); |
21 | | - this.state.onSelectedStepIdChanged.subscribe(handler); |
22 | | - this.state.onIsDragDisabledChanged.subscribe(handler); |
23 | | - if (this.isUndoRedoSupported()) { |
24 | | - this.state.onDefinitionChanged.subscribe(handler); |
25 | | - } |
| 37 | + this.onStateChanged.subscribe(handler); |
26 | 38 | } |
27 | 39 |
|
28 | 40 | public resetViewport() { |
|
0 commit comments