-
Notifications
You must be signed in to change notification settings - Fork 186
/
Copy pathAsyncMemoryStore.js
61 lines (50 loc) · 1.19 KB
/
AsyncMemoryStore.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
define([
"dojo/_base/declare",
"dojo/Deferred",
"dojo/store/Memory",
"dojo/store/util/QueryResults",
"dojo/store/util/SimpleQueryEngine"
], function(declare, Deferred, Memory, QueryResults, SimpleQueryEngine){
// module:
// dijit/tests/AsyncMemoryStore
return declare(null, {
// summary:
// Wrapper on dojo/store/Memory that makes functions async (for testing)
queryEngine: SimpleQueryEngine,
constructor: function(hash){
this.store = new Memory(hash);
},
get: function(id){
var d = new Deferred(), store = this.store;
try{
d.resolve(store.get(id));
}catch(e){
d.reject(e);
}
return d;
},
getIdentity: function(object){
return this.store.getIdentity(object);
},
put: function(object, directives){
return this.store.put(object, directives);
},
add: function(object, directives){
return this.store.add(object, directives);
},
remove: function(id){
return this.store.remove(id);
},
query: function(query, options){
var d = new Deferred(), store = this.store;
setTimeout(function(){
try{
d.resolve(store.query(query, options));
}catch(e){
d.reject(e);
}
}, 10);
return QueryResults(d);
}
});
});