Skip to content

Commit

Permalink
added remote update for wss plug. Fixed various bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyGermaneri committed Jan 28, 2024
1 parent 9c2b588 commit c073335
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 11 deletions.
4 changes: 2 additions & 2 deletions packages/CodeEditor/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export default {
cursorLocation: null,
updatingValue: false,
editorHasFocus: false,
autosave: true,
autosave: false,
messageIds: [],
externalErrors: [],
loaded: false,
Expand Down Expand Up @@ -449,7 +449,7 @@ export default {
clearTimeout(this.saveDebounceTimer);
this.saveDebounceTimer = setTimeout(() => {
this.save();
}, 500);
}, 4000);
}
},
revert() {
Expand Down
4 changes: 3 additions & 1 deletion packages/Graph/GraphCanvas.vue
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ export default {
graphCanvasStyle: function () {
if (this.presentation) {
return {
display: "flex"
overflow: "auto",
height: "100vh",
width: "100vw",
};
}
return {
Expand Down
23 changes: 19 additions & 4 deletions packages/Graph/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,9 +428,11 @@ export default {
});
this.historyPosition += 1;
// make a copy of the change in the snapshot store for data providers
this.graphSnapshotStore.$patch({
graph: deref(this.graph),
this.updatingSnapshotLocally = true;
this.graphSnapshotStore.$patch((state: any) => {
state.graph = deref(this.graph);
});
this.updatingSnapshotLocally = false;
},
async loadAllScripts(graphSnapshot: any) {
// Extracting the root-level scripts
Expand Down Expand Up @@ -476,6 +478,18 @@ export default {
await this.loadAllScripts(this.graphSnapshot);
// don't allow an opening graph to count as a history change
this.graph = deref(this.graphSnapshot);
this.graphSnapshotStore.$subscribe((mutation: any, state: any) => {
if (this.updatingSnapshotLocally) {
return;
}
const changes = diff(this.graph, state.graph);
if (changes) {
changes.forEach((change: any) => {
applyChange(this.graphSnapshot, true, change);
});
this.graph = deref(this.graphSnapshot);
}
});
console.groupCollapsed('%cPlastic-IO: %cGraph',
"color: blue",
"color: lightblue");
Expand Down Expand Up @@ -641,19 +655,20 @@ export default {
pos.x = Math.floor(pos.x / 10) * 10;
pos.y = Math.floor(pos.y / 10) * 10;
const id = newId();
const name = getName();
const node = {
id,
edges: [],
version: this.graphSnapshot!.version,
graphId: this.graphSnapshot!.id,
artifact: null,
url: getName().replace(/ /g, ''),
url: name.replace(/ /g, ''),
data: null,
properties: {
inputs: [],
outputs: [],
groups: [],
name: "",
name,
description: "",
tags: [],
icon: "mdi-node-rectangle",
Expand Down
1 change: 1 addition & 0 deletions packages/Graph/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export default () => {
preferencesStore: usePreferencesStore(),
graphSnapshotStore: useGraphSnapshotStore(),
graphSnapshot: null as any,
updatingSnapshotLocally: false,
rewindVersion: 0,
keys: {} as Record<string, string>,
artifacts: {} as Record<string, any>,
Expand Down
6 changes: 6 additions & 0 deletions packages/Input/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ export const useStore = defineStore('input', {
this.mouseAction.mouse(mouse);
},
onwheel(e: WheelEvent) {
if (this.graphStore.presentation) {
return;
}
if (!this.graphStore.isGraphTarget(e)) {
return;
}
Expand All @@ -52,6 +55,9 @@ export const useStore = defineStore('input', {
e.preventDefault();
},
mousemove(e: MouseEvent) {
if (this.graphStore.presentation) {
return;
}
if (this.orchistratorStore.showHelp || this.graphStore.inRewindMode) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/NodeEdgeConnector/NodeEdgeConnector.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div>
<div v-if="!presentation">
<div :class="{'connector-info-value': true, 'connector-info-value-expanded': expand}"
v-if="preferences.showConnectorActivity && activityValue"
@mousemove.stop
Expand Down
36 changes: 33 additions & 3 deletions packages/WssDocumentProvider/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ export default class WssDocumentProvider extends EditorModule {
constructor(config: Record<string, any>, app: App<Element>, hostRouter: Router) {
super();
const providerState = {
graph: {} as any,
graph: null as any,
localUpdate: false,
sentEventIds: [],
};
const orchistratorStore = useOrchistratorStore();
const graphSnapshotStore = useGraphSnapshotStore();
Expand All @@ -30,7 +32,34 @@ export default class WssDocumentProvider extends EditorModule {
() => {},
);
graphStore.$subscribe((mutation: any, state: any) => {
if (!state.graph) {
if (!state.graph || providerState.localUpdate) {
return;
}
if (!providerState.graph) {
// inital load
providerState.graph = JSON.parse(JSON.stringify(state.graph));
// messages from server
orchistratorStore.dataProviders.graph.subscribe('graph-event-' + providerState.graph.id, async (e: any) => {
// apply remote event
graphSnapshotStore.$patch((state) => {
providerState.localUpdate = true;
e.forEach((event) => {
if (providerState.sentEventIds.includes(event.id)) {
return;
}
// apply changes to the graphStore
event.changes.forEach((change: any) => {
applyChange(state.graph, true, change);
});
// clone graph store to keep provider state up to date
providerState.graph = JSON.parse(JSON.stringify(state.graph));
providerState.localUpdate = false;
});
});
});
return;
}
if (mutation.type !== 'patch function') {
return;
}
const changes = diff(providerState.graph || {}, JSON.parse(JSON.stringify(state.graph)));
Expand All @@ -42,9 +71,11 @@ export default class WssDocumentProvider extends EditorModule {
description: '',
graphId: state.graph!.id,
};
providerState.sentEventIds.push(ev.id);
wssDataProvider.set(state.graph!.url, ev as any);
}
}, { detached: true });

(orchistratorStore.dataProviders.graph as any) = wssDataProvider;
let writeDebounceTimer: any;
(orchistratorStore.dataProviders as any).publish = wssDataProvider;
Expand All @@ -54,7 +85,6 @@ export default class WssDocumentProvider extends EditorModule {
return await wssDataProvider.getToc();
},
updateToc(key: string, value: any) {
console.log('updateToc');
orchistratorStore.toc[key] = value;
},
};
Expand Down

0 comments on commit c073335

Please sign in to comment.