Skip to content

Commit

Permalink
Create WorkflowDoc YDocument
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii-i committed Dec 6, 2024
1 parent 025c390 commit 644b423
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/workflows/workflowDoc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { YDocument } from '@jupyter/ydoc';
import * as Y from 'yjs';
import { Workflow, Task } from './_interface/workflow.schema';

export class WorkflowDoc extends YDocument<WorkflowChange> implements Workflow {
private _tasks: Y.Array<Y.Map<any>>;
private _name: Y.Text;
private _parameters: Y.Map<string>;
private _schedule: Y.Text;
private _timezone: Y.Text;

constructor() {
super();

this._tasks = this.ydoc.getArray<Y.Map<any>>('tasks');
this._name = this.ydoc.getMap<string>('name');
this._parameters = this.ydoc.getMap<any>('parameters');
this._schedule = this.ydoc.getMap<string>('schedule');
this._timezone = this.ydoc.getMap<string>('timezone');

this._tasks.observeDeep(this._tasksObserver);
//TODO: add other observers
}

// Getter and setter methods
get tasks(): Task[] {
return this._tasks.map(task => task.toJSON() as Task);
}

set tasks(value: Task[]) {
this.transact(() => {
this._tasks.delete(0, this._tasks.length);
value.forEach(task => {
this._tasks.push([Y.Map.from(Object.entries(task))]);
});
});
}

//TODO: add other getters/setters

private _tasksObserver = (events: Y.YEvent<any>[]) => {
// TODO: Handle task changes
};
}

0 comments on commit 644b423

Please sign in to comment.