forked from svt/bridge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSState.js
63 lines (55 loc) · 1.39 KB
/
SState.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// SPDX-FileCopyrightText: 2022 Sveriges Television AB
//
// SPDX-License-Identifier: MIT
const objectPath = require('object-path')
const DIController = require('../../shared/DIController')
const DIBase = require('../../shared/DIBase')
class SState extends DIBase {
/**
* @type { Map.<String, Map.<String, Handler> }
*/
#events = new Map()
constructor (...args) {
super(...args)
this.#setup()
}
#setup () {
this.props.SCommands.registerCommand('state.apply', this.applyState.bind(this))
this.props.SCommands.registerAsyncCommand('state.get', this.getState.bind(this))
}
/**
* Apply some arbitrary
* data to the state
*
* This function only exists
* to run the apply function
* the correct scope
* @param { Object } set Some data to set
*/
applyState (set, transparent) {
this.props.Workspace.state.apply(set, transparent)
}
/**
* Get the current
* full state or part
* of the state using a
* dot-notation path
* @param { String } path An optional path for only
* getting part of the state
* @returns { any }
*//**
* Get the full state
* @returns { any }
*/
getState (path) {
const data = this.props.Workspace.state.data
if (path) {
return objectPath.get(data, path)
}
return data
}
}
DIController.main.register('SState', SState, [
'Workspace',
'SCommands'
])