-
Notifications
You must be signed in to change notification settings - Fork 0
/
FuncSpace.js
52 lines (45 loc) · 1.33 KB
/
FuncSpace.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
class FuncSpace {
static c = FuncSpace.getFuncid();
static global_space_var = "FuncSpace";
static funcs = FuncSpace.getFuncs();
/**
* generates a new name that has not bee used before
* */
static newName() {
FuncSpace.c+=1;
Jupyter.notebook.metadata.nodes.funcid = FuncSpace.c;
name = FuncSpace.global_space_var+"_func_"+FuncSpace.c; // get the variable contained by the nodespace variable on the python side
FuncSpace.funcs.push(name);
return name
}
/**
* return the currenct funcid so that new names can be generated and not collide with old ones
* */
static getFuncid() {
if (Jupyter.notebook.metadata.nodes && Jupyter.notebook.metadata.nodes.funcid) return Jupyter.notebook.metadata.nodes.funcid;
return 0;
}
/**
* get a list of allocated functions
* */
static getFuncs() {
if (Jupyter.notebook.metadata.nodes && Jupyter.notebook.metadata.nodes.funcs) return Jupyter.notebook.metadata.nodes.funcs;
return [];
}
/**
* add a function, and make sure there are no duplicates
* */
static addFunc(func) {
if (!FuncSpace.funcs.includes(func)) {
FuncSpace.funcs.push(func);
}
}
/**
* deallocate function
* */
static removeFunc(func) {
if (!FuncSpace.funcs.includes(func)) {
FuncSpace.funcs.splice(FuncSpace.funcs.indexOf(func), 1);
}
}
}