forked from emberjs/data
/
model_array.js
70 lines (53 loc) · 1.71 KB
/
model_array.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
59
60
61
62
63
64
65
66
67
68
69
70
var get = SC.get, set = SC.set;
DS.ModelArray = SC.ArrayProxy.extend({
type: null,
content: null,
store: null,
init: function() {
set(this, 'modelCache', Ember.A([]));
this._super();
},
arrayDidChange: function(array, index, removed, added) {
var modelCache = get(this, 'modelCache');
modelCache.replace(index, 0, Array(added));
this._super(array, index, removed, added);
},
arrayWillChange: function(array, index, removed, added) {
this._super(array, index, removed, added);
var modelCache = get(this, 'modelCache');
modelCache.replace(index, removed);
},
objectAtContent: function(index) {
var modelCache = get(this, 'modelCache');
var model = modelCache.objectAt(index);
if (!model) {
var store = get(this, 'store');
var content = get(this, 'content');
var contentObject = content.objectAt(index);
if (contentObject !== undefined) {
model = store.findByClientId(get(this, 'type'), contentObject);
modelCache.replace(index, 1, [model]);
}
}
return model;
}
});
DS.FilteredModelArray = DS.ModelArray.extend({
filterFunction: null,
updateFilter: SC.observer(function() {
var store = get(this, 'store');
store.updateModelArrayFilter(this, get(this, 'type'), get(this, 'filterFunction'));
}, 'filterFunction')
});
DS.AdapterPopulatedModelArray = DS.ModelArray.extend({
query: null,
isLoaded: false,
load: function(array) {
var store = get(this, 'store'), type = get(this, 'type');
var clientIds = store.loadMany(type, array).clientIds;
this.beginPropertyChanges();
set(this, 'content', Ember.A(clientIds));
set(this, 'isLoaded', true);
this.endPropertyChanges();
}
});