File tree 1 file changed +44
-0
lines changed
1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { YDocument } from '@jupyter/ydoc' ;
2
+ import * as Y from 'yjs' ;
3
+ import { Workflow , Task } from './_interface/workflow.schema' ;
4
+
5
+ export class WorkflowDoc extends YDocument < WorkflowChange > implements Workflow {
6
+ private _tasks : Y . Array < Y . Map < any > > ;
7
+ private _name : Y . Text ;
8
+ private _parameters : Y . Map < string > ;
9
+ private _schedule : Y . Text ;
10
+ private _timezone : Y . Text ;
11
+
12
+ constructor ( ) {
13
+ super ( ) ;
14
+
15
+ this . _tasks = this . ydoc . getArray < Y . Map < any > > ( 'tasks' ) ;
16
+ this . _name = this . ydoc . getText ( 'name' ) ;
17
+ this . _parameters = this . ydoc . getMap < string > ( 'parameters' ) ;
18
+ this . _schedule = this . ydoc . getText ( 'schedule' ) ;
19
+ this . _timezone = this . ydoc . getText ( 'timezone' ) ;
20
+
21
+ this . _tasks . observeDeep ( this . _tasksObserver ) ;
22
+ //TODO: add other observers
23
+ }
24
+
25
+ // Getter and setter methods
26
+ get tasks ( ) : Task [ ] {
27
+ return this . _tasks . map ( task => task . toJSON ( ) as Task ) ;
28
+ }
29
+
30
+ set tasks ( value : Task [ ] ) {
31
+ this . transact ( ( ) => {
32
+ this . _tasks . delete ( 0 , this . _tasks . length ) ;
33
+ value . forEach ( task => {
34
+ this . _tasks . push ( [ Y . Map . from ( Object . entries ( task ) ) ] ) ;
35
+ } ) ;
36
+ } ) ;
37
+ }
38
+
39
+ //TODO: add other getters/setters
40
+
41
+ private _tasksObserver = ( events : Y . YEvent < any > [ ] ) => {
42
+ // TODO: Handle task changes
43
+ } ;
44
+ }
You can’t perform that action at this time.
0 commit comments