-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDCDocument.dart
More file actions
52 lines (44 loc) · 1.25 KB
/
DCDocument.dart
File metadata and controls
52 lines (44 loc) · 1.25 KB
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
/**
* The principle data structure of dcache, representing a document
* ---
*/
class DCDocument extends Object
{
Map<String,Dynamic> _data;
DCDocument ([String id])
{
_data = new Map<String,Dynamic>();
if(id != null) {
this["_id"] = id;
}
else {
this["_id"] = new Date.now().millisecondsSinceEpoch.toString();
}
}
static DCDocument fromJSON (String jsonString)
{
var doc = new DCDocument();
doc._data = JSON.parse(jsonString);
return doc;
}
noSuchMethod(String function_name, List args)
{
if (args.length == 0 && function_name.startsWith("get:"))
{
var property = function_name.replaceFirst("get:", "");
if (this._data.containsKey(property)) {
return this[property];
}
}
else if (args.length == 1 && function_name.startsWith("set:")) {
var property = function_name.replaceFirst("set:", "");
this[property] = args[0];
return this[property];
}
super.noSuchMethod(function_name, args);
}
toString() => JSON.stringify(this._data);
Map toMap() => new Map.from(this._data);
operator [] (key) => this._data[key];
operator []= (key,value) => this._data[key] = value;
}