1 | 'use strict';
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | var EntityPool;
|
8 |
|
9 | EntityPool = (function() {
|
10 | function EntityPool() {}
|
11 |
|
12 |
|
13 | |
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | EntityPool.prototype.set = function(model) {
|
20 | var Model, modelName;
|
21 | Model = model.constructor;
|
22 | if (!Model.isEntity || ((model != null ? model.id : void 0) == null)) {
|
23 | return;
|
24 | }
|
25 | modelName = Model.getName();
|
26 | if (EntityPool.prototype[modelName]) {
|
27 | throw new Error("invalid model name " + modelName);
|
28 | }
|
29 | if (this[modelName] == null) {
|
30 | this[modelName] = {};
|
31 | }
|
32 | return this[modelName][model.id] = model;
|
33 | };
|
34 |
|
35 |
|
36 | |
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 | EntityPool.prototype.get = function(modelName, id) {
|
46 | var ref;
|
47 | return (ref = this[modelName]) != null ? ref[id] : void 0;
|
48 | };
|
49 |
|
50 |
|
51 | |
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 | EntityPool.prototype.clear = function() {
|
58 | var id, modelName, models, results;
|
59 | results = [];
|
60 | for (modelName in this) {
|
61 | models = this[modelName];
|
62 | for (id in models) {
|
63 | delete models[id];
|
64 | }
|
65 | results.push(delete models[modelName]);
|
66 | }
|
67 | return results;
|
68 | };
|
69 |
|
70 | return EntityPool;
|
71 |
|
72 | })();
|
73 |
|
74 | module.exports = EntityPool;
|