Skip to main content

jellyflow_runtime/runtime/store/view/
config.rs

1use crate::io::{
2    NodeGraphEditorConfig, NodeGraphInteractionConfig, NodeGraphInteractionState,
3    NodeGraphRuntimeTuning,
4};
5
6use super::super::NodeGraphStore;
7
8impl NodeGraphStore {
9    pub fn interaction(&self) -> &NodeGraphInteractionConfig {
10        &self.interaction
11    }
12
13    pub fn runtime_tuning(&self) -> &NodeGraphRuntimeTuning {
14        &self.runtime_tuning
15    }
16
17    pub fn editor_config(&self) -> NodeGraphEditorConfig {
18        NodeGraphEditorConfig::from_parts(self.interaction.clone(), self.runtime_tuning)
19    }
20
21    pub fn resolved_interaction_state(&self) -> NodeGraphInteractionState {
22        NodeGraphInteractionState::from_parts(&self.interaction, &self.runtime_tuning)
23    }
24
25    pub fn replace_editor_config(&mut self, editor_config: NodeGraphEditorConfig) {
26        self.install_editor_config_if_changed(editor_config);
27    }
28
29    pub fn update_editor_config(&mut self, f: impl FnOnce(&mut NodeGraphEditorConfig)) {
30        let mut next = self.editor_config();
31        f(&mut next);
32        self.install_editor_config_if_changed(next);
33    }
34
35    fn install_editor_config_if_changed(&mut self, editor_config: NodeGraphEditorConfig) {
36        if self.interaction == editor_config.interaction
37            && self.runtime_tuning == editor_config.runtime_tuning
38        {
39            return;
40        }
41
42        self.interaction = editor_config.interaction;
43        self.runtime_tuning = editor_config.runtime_tuning;
44        self.notify_selectors();
45    }
46}