-
Notifications
You must be signed in to change notification settings - Fork 20
/
Repository.js
58 lines (37 loc) · 1.07 KB
/
Repository.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
53
54
55
56
57
58
/**
* Ternific Copyright (c) 2014 Miguel Castillo.
*
* Licensed under MIT
*/
define(function (/*require, exports, module*/) {
"use strict";
var _ = brackets.getModule("thirdparty/lodash");
function Repository() {
this._items = [];
}
Repository.prototype.add = function(document) {
this._items.push(document);
};
Repository.prototype.remove = function(document) {
var i = this._items.indexOf(document);
if (i !== -1) {
this._items.splice(i, 1);
}
};
Repository.prototype.clear = function() {
this._items.splice(0, Number.MAX_VALUE);
};
Repository.prototype.items = function() {
return this._items.slice();
};
Repository.prototype.find = function(criteria) {
return _.find(this._items, criteria);
};
Repository.prototype.getByName = function(name) {
return _.find(this._items, {"name": name});
};
Repository.prototype.getById = function(id) {
return _.find(this._items, {"id": id});
};
return Repository;
});