-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathdictionary.js
More file actions
121 lines (102 loc) · 3.07 KB
/
dictionary.js
File metadata and controls
121 lines (102 loc) · 3.07 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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/**
* @fileoverview A wrapper for dicts.
*/
goog.provide('ee.Dictionary');
goog.require('ee.ApiFunction');
goog.require('ee.ComputedObject');
goog.require('ee.Types');
goog.require('ee.rpc_node');
goog.requireType('ee.Encodable');
goog.requireType('ee.api');
/**
* Constructs a new Dictionary.
*
* @param {Object|ee.ComputedObject=} opt_dict An object to convert to
* a dictionary. This constructor accepts the following types:
* 1) Another dictionary.
* 2) A list of key/value pairs.
* 3) A null or no argument (producing an empty dictionary)
*
* @constructor
* @extends {ee.ComputedObject}
* @export
*/
ee.Dictionary = function(opt_dict) {
// Constructor safety.
if (!(this instanceof ee.Dictionary)) {
return ee.ComputedObject.construct(ee.Dictionary, arguments);
} else if (opt_dict instanceof ee.Dictionary) {
return opt_dict;
}
ee.Dictionary.initialize();
/**
* The internal rerpresentation of this dictionary.
*
* @type {Object}
* @private
*/
this.dict_;
if (ee.Types.isRegularObject(opt_dict)) {
// Cast to a dictionary.
ee.Dictionary.base(this, 'constructor', null, null);
this.dict_ = /** @type {!Object} */ (opt_dict);
} else {
if (opt_dict instanceof ee.ComputedObject && opt_dict.func &&
opt_dict.func.getSignature()['returns'] == 'Dictionary') {
// If it's a call that's already returning a Dictionary, just cast.
ee.Dictionary.base(this, 'constructor', opt_dict.func, opt_dict.args, opt_dict.varName, opt_dict.unbound);
} else {
const unbound =
opt_dict instanceof ee.ComputedObject ? opt_dict.unbound : null;
// Delegate everything else to the server-side constructor.
ee.Dictionary.base(
this, 'constructor', new ee.ApiFunction('Dictionary'),
{'input': opt_dict}, null, unbound);
}
this.dict_ = null;
}
};
goog.inherits(ee.Dictionary, ee.ComputedObject);
/**
* Whether the class has been initialized with API functions.
* @type {boolean}
* @private
*/
ee.Dictionary.initialized_ = false;
/** Imports API functions to this class. */
ee.Dictionary.initialize = function() {
if (!ee.Dictionary.initialized_) {
ee.ApiFunction.importApi(ee.Dictionary, 'Dictionary', 'Dictionary');
ee.Dictionary.initialized_ = true;
}
};
/** Removes imported API functions from this class. */
ee.Dictionary.reset = function() {
ee.ApiFunction.clearApi(ee.Dictionary);
ee.Dictionary.initialized_ = false;
};
/**
* @override
*/
ee.Dictionary.prototype.encode = function(encoder) {
if (this.dict_ !== null) {
return encoder(this.dict_);
} else {
return ee.Dictionary.base(this, 'encode', encoder);
}
};
/** @override @return {!ee.api.ValueNode} */
ee.Dictionary.prototype.encodeCloudValue = function(
/** !ee.Encodable.Serializer */ serializer) {
if (this.dict_ !== null) {
return ee.rpc_node.reference(serializer.makeReference(this.dict_));
} else {
return ee.Dictionary.base(this, 'encodeCloudValue', serializer);
}
};
/**
* @override
*/
ee.Dictionary.prototype.name = function() {
return 'Dictionary';
};