forked from ibm-js/delite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DstoreQueryAdapter.js
96 lines (86 loc) · 2.25 KB
/
DstoreQueryAdapter.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/** @module delite/DstoreQueryAdapter */
define([
"dcl/dcl"
], function (dcl) {
/**
* An adapter to use dstore/Store in the `source` of delite/Store.js.
* Created to keep a common interface with the use of an array instead of dstore/Store.
* The arguments to pass to the constructor are:
*
* - source: dstore/Store - the dstore/Store represented by the adapter.
* - query: the query filter to apply to the store.
* - processQueryResult: function to apply to the store.
*
* @class module:delite/DstoreQueryAdapter
*/
return dcl(/** @lends module:delite/DstoreQueryAdapter# */ {
declaredClass: "delite/DstoreQueryAdapter",
constructor: function (args) {
this.source = args.source;
this.data = args.processQueryResult(this.source.filter(args.query));
if (this.data.track) {
this.data = this._tracked = this.data.track();
this.track = true;
}
},
/**
* Indicates if the source is trackable.
* @member {boolean}
* @default false
* @readonly
*/
track: false,
/**
* Remove the trackability of the dstore.
*/
untrack: function () {
if (this._tracked) {
this._tracked.tracking.remove();
this._tracked = null;
}
},
/**
* Perform the fetch operation on the collection.
*/
fetch: function () {
return this.data.fetch();
},
/**
* Perform the fetchRange operation on the collection.
* @param {Object} args - contains the start index and the end index of the fetch.
*/
fetchRange: function (args) {
return this.data.fetchRange(args);
},
/**
* Bind the listener of the adapter with the events send by the dstore/Trackable.
* @param type
* @param listener
* @returns {Object} Handle with `remove()` method to cancel the listener.
*/
on: function (type, listener) {
return this.data.on(type, listener);
},
/**
* Set the identity of an object.
*/
setIdentity: function (item, id) {
this.source._setIdentity(item, id);
},
/**
* Retrieve an object in the data by its identity.
*/
get: function (id) {
return this.source.get(id);
},
/**
* Return the identity of an item.
* @param {Object} item - The item.
* @returns {*}
* @protected
*/
getIdentity: function (item) {
return this.source.getIdentity(item);
}
});
});