ElementTemplates.js
1.03 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
55
56
'use strict';
var values = require('lodash/values');
/**
* The guy knowing all configured element templates.
*
* This registry won't validate. Use the {@link Validator}
* to verify a template is valid prior to adding it to
* this registry.
*/
function ElementTemplates() {
this._templates = {};
/**
* Sets the known element templates.
*
* @param {Array<TemplateDescriptor>} descriptors
*
* @return {ElementTemplates}
*/
this.set = function(descriptors) {
var templates = this._templates = {};
descriptors.forEach(function(descriptor) {
templates[descriptor.id] = descriptor;
});
return this;
};
/**
* Get template descriptor with given id.
*
* @param {String} id
*
* @return {TemplateDescriptor}
*/
this.get = function(id) {
return this._templates[id];
};
/**
* Return all known template descriptors.
*
* @return {Array<TemplateDescriptor>}
*/
this.getAll = function() {
return values(this._templates);
};
}
module.exports = ElementTemplates;