Skip to content

Commit 2d86eb7

Browse files
committed
AgentOS.canvas.Blackboard: refactoring
1 parent a7030bc commit 2d86eb7

File tree

1 file changed

+35
-29
lines changed

1 file changed

+35
-29
lines changed

apps/agentos/canvas/Blackboard.mjs

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,6 @@ import Base from '../../../src/core/Base.mjs';
66
* @singleton
77
*/
88
class Blackboard extends Base {
9-
/**
10-
* @member {String|null} canvasId=null
11-
*/
12-
canvasId = null
13-
/**
14-
* @member {Object} canvasSize=null
15-
*/
16-
canvasSize = null
17-
/**
18-
* @member {Object} context=null
19-
*/
20-
context = null
21-
/**
22-
* @member {Array} nodes=[]
23-
*/
24-
nodes = []
25-
/**
26-
* @member {Array} links=[]
27-
*/
28-
links = []
29-
309
static config = {
3110
/**
3211
* @member {String} className='AgentOS.canvas.Blackboard'
@@ -52,6 +31,27 @@ class Blackboard extends Base {
5231
singleton: true
5332
}
5433

34+
/**
35+
* @member {String|null} canvasId=null
36+
*/
37+
canvasId = null
38+
/**
39+
* @member {Object} canvasSize=null
40+
*/
41+
canvasSize = null
42+
/**
43+
* @member {Object} context=null
44+
*/
45+
context = null
46+
/**
47+
* @member {Array} links=[]
48+
*/
49+
links = []
50+
/**
51+
* @member {Array} nodes=[]
52+
*/
53+
nodes = []
54+
5555
construct(config) {
5656
super.construct(config);
5757
// Seed some dummy data for initial render verification
@@ -68,23 +68,29 @@ class Blackboard extends Base {
6868

6969
/**
7070
* Initialize the graph with a canvas ID
71-
* @param {String} canvasId
71+
* @param {Object} opts
72+
* @param {String} opts.canvasId
73+
* @param {String} opts.windowId
7274
*/
73-
initGraph(canvasId) {
74-
console.log('Blackboard: initGraph', canvasId);
75+
initGraph({canvasId, windowId}) {
76+
let me = this,
77+
hasChange = me.canvasId !== canvasId;
78+
79+
console.log('Blackboard: initGraph', canvasId, hasChange);
7580
this.canvasId = canvasId;
7681

7782
// Wait for the canvas to be available in the worker map
7883
const checkCanvas = () => {
79-
const canvas = Neo.currentWorker.map[canvasId];
84+
const canvas = Neo.currentWorker.canvasWindowMap[canvasId]?.[windowId];
85+
8086
if (canvas) {
81-
this.context = canvas.getContext('2d');
82-
this.render();
87+
me.context = canvas.getContext('2d');
88+
hasChange && me.render()
8389
} else {
84-
setTimeout(checkCanvas, 50);
90+
setTimeout(checkCanvas, 50)
8591
}
8692
};
87-
checkCanvas();
93+
checkCanvas()
8894
}
8995

9096
updateGraphData(data) {

0 commit comments

Comments
 (0)