|
1 | 1 | import type { TimelinePersistentState } from '@sofie-automation/blueprints-integration' |
2 | 2 | import type { BlueprintPlayoutPersistentStore } from '@sofie-automation/blueprints-integration/dist/context/playoutStore' |
3 | 3 | import { clone } from '@sofie-automation/corelib/dist/lib' |
| 4 | +import type { PlayoutModel } from '../../../playout/model/PlayoutModel.js' |
4 | 5 |
|
5 | 6 | export class PersistentPlayoutStateStore implements BlueprintPlayoutPersistentStore { |
6 | | - #state: TimelinePersistentState | undefined |
7 | | - #hasChanges = false |
| 7 | + #privateState: TimelinePersistentState | undefined |
| 8 | + #hasPrivateChanges = false |
| 9 | + #publicState: TimelinePersistentState | undefined |
| 10 | + #hasPublicChanges = false |
8 | 11 |
|
9 | | - get hasChanges(): boolean { |
10 | | - return this.#hasChanges |
| 12 | + constructor(privateState: TimelinePersistentState | undefined, publicState: TimelinePersistentState | undefined) { |
| 13 | + this.#privateState = clone(privateState) |
| 14 | + this.#publicState = clone(publicState) |
11 | 15 | } |
12 | 16 |
|
13 | | - constructor(state: TimelinePersistentState | undefined) { |
14 | | - this.#state = clone(state) |
| 17 | + saveToModel(model: PlayoutModel): void { |
| 18 | + if (this.#hasPrivateChanges) model.setBlueprintPrivatePersistentState(this.#privateState) |
| 19 | + if (this.#hasPublicChanges) model.setBlueprintPublicPersistentState(this.#publicState) |
15 | 20 | } |
16 | 21 |
|
17 | 22 | getAll(): Partial<unknown> { |
18 | | - return this.#state || {} |
| 23 | + return this.#privateState || {} |
19 | 24 | } |
20 | 25 | getKey<K extends never>(k: K): unknown { |
21 | | - return this.#state?.[k] |
| 26 | + return this.#privateState?.[k] |
22 | 27 | } |
23 | 28 | setKey<K extends never>(k: K, v: unknown): void { |
24 | | - if (!this.#state) this.#state = {} |
25 | | - ;(this.#state as any)[k] = v |
26 | | - this.#hasChanges = true |
| 29 | + if (!this.#privateState) this.#privateState = {} |
| 30 | + ;(this.#privateState as any)[k] = v |
| 31 | + this.#hasPrivateChanges = true |
27 | 32 | } |
28 | 33 | setAll(obj: unknown): void { |
29 | | - this.#state = obj |
30 | | - this.#hasChanges = true |
| 34 | + this.#privateState = obj |
| 35 | + this.#hasPrivateChanges = true |
| 36 | + } |
| 37 | + |
| 38 | + getAllPublic(): Partial<unknown> { |
| 39 | + return this.#publicState || {} |
| 40 | + } |
| 41 | + getKeyPublic<K extends never>(k: K): unknown { |
| 42 | + return this.#publicState?.[k] |
| 43 | + } |
| 44 | + setKeyPublic<K extends never>(k: K, v: unknown): void { |
| 45 | + if (!this.#publicState) this.#publicState = {} |
| 46 | + ;(this.#publicState as any)[k] = v |
| 47 | + this.#hasPublicChanges = true |
| 48 | + } |
| 49 | + setAllPublic(obj: unknown): void { |
| 50 | + this.#publicState = obj |
| 51 | + this.#hasPublicChanges = true |
31 | 52 | } |
32 | 53 | } |
0 commit comments