| 1 |
define([ |
| 2 |
"dojo/_base/declare", |
| 3 |
"dojo/Deferred", |
| 4 |
"dojo/store/Memory", |
| 5 |
"dojo/store/util/QueryResults", |
| 6 |
"dojo/store/util/SimpleQueryEngine" |
| 7 |
], function(declare, Deferred, Memory, QueryResults, SimpleQueryEngine){ |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
return declare(null, { |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
queryEngine: SimpleQueryEngine, |
| 17 |
|
| 18 |
constructor: function(hash){ |
| 19 |
this.store = new Memory(hash); |
| 20 |
}, |
| 21 |
|
| 22 |
get: function(id){ |
| 23 |
var d = new Deferred(), store = this.store; |
| 24 |
try{ |
| 25 |
d.resolve(store.get(id)); |
| 26 |
}catch(e){ |
| 27 |
d.reject(e); |
| 28 |
} |
| 29 |
return d; |
| 30 |
}, |
| 31 |
|
| 32 |
getIdentity: function(object){ |
| 33 |
return this.store.getIdentity(object); |
| 34 |
}, |
| 35 |
|
| 36 |
put: function(object, directives){ |
| 37 |
return this.store.put(object, directives); |
| 38 |
}, |
| 39 |
|
| 40 |
add: function(object, directives){ |
| 41 |
return this.store.add(object, directives); |
| 42 |
}, |
| 43 |
|
| 44 |
remove: function(id){ |
| 45 |
return this.store.remove(id); |
| 46 |
|
| 47 |
}, |
| 48 |
|
| 49 |
query: function(query, options){ |
| 50 |
var d = new Deferred(), store = this.store; |
| 51 |
setTimeout(function(){ |
| 52 |
try{ |
| 53 |
d.resolve(store.query(query, options)); |
| 54 |
}catch(e){ |
| 55 |
d.reject(e); |
| 56 |
} |
| 57 |
}, 10); |
| 58 |
return QueryResults(d); |
| 59 |
} |
| 60 |
}); |
| 61 |
}); |