-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathregistry.js
More file actions
54 lines (46 loc) · 1.36 KB
/
registry.js
File metadata and controls
54 lines (46 loc) · 1.36 KB
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
53
54
define(["dojo/has"], function (has) {
has.add("gfxRegistry", 1);
var registry = {};
// a set of ids (keys=type)
var _ids = {};
// a simple set impl to map shape<->id
var hash = {};
registry.register = function (/*gfx/shape.Shape*/s) {
// summary:
// Register the specified shape into the graphics registry.
// s: gfx/shape.Shape
// The shape to register.
// returns: Number
// The unique id associated with this shape.
// the id pattern : type+number (ex: Rect0,Rect1,etc)
// declaredClass is now optional with dcl
var t = s.declaredClass ? s.declaredClass.split(".").pop() : "Shape";
var i = t in _ids ? ++_ids[t] : ((_ids[t] = 0));
var uid = t + i;
hash[uid] = s;
return uid;
};
registry.byId = function (/*String*/id) {
// summary:
// Returns the shape that matches the specified id.
// id: String
// The unique identifier for this Shape.
// returns: gfx/shape.Shape
return hash[id]; //gfx/shape.Shape
};
registry.dispose = function (/*gfx/shape.Shape*/s, /*Boolean?*/recurse) {
// summary:
// Removes the specified shape from the registry.
// s: gfx/shape.Shape
// The shape to unregister.
if (recurse && s.children) {
for (var i = 0; i < s.children.length; ++i) {
registry.dispose(s.children[i], true);
}
}
var uid = s.getUID();
hash[uid] = null;
delete hash[uid];
};
return registry;
});