@webex/internal-plugin-device 2.59.3-next.1 → 2.59.4-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +6 -6
- package/README.md +80 -80
- package/babel.config.js +3 -3
- package/dist/config.js +27 -27
- package/dist/config.js.map +1 -1
- package/dist/constants.js.map +1 -1
- package/dist/device.js +226 -226
- package/dist/device.js.map +1 -1
- package/dist/features/feature-collection.js +14 -14
- package/dist/features/feature-collection.js.map +1 -1
- package/dist/features/feature-model.js +78 -79
- package/dist/features/feature-model.js.map +1 -1
- package/dist/features/features-model.js +28 -28
- package/dist/features/features-model.js.map +1 -1
- package/dist/features/index.js.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/interceptors/device-url.js +10 -10
- package/dist/interceptors/device-url.js.map +1 -1
- package/dist/metrics.js.map +1 -1
- package/jest.config.js +3 -3
- package/package.json +10 -10
- package/process +1 -1
- package/src/config.js +60 -60
- package/src/constants.js +23 -23
- package/src/device.js +835 -835
- package/src/features/feature-collection.js +30 -30
- package/src/features/feature-model.js +189 -189
- package/src/features/features-model.js +96 -96
- package/src/features/index.js +5 -5
- package/src/index.js +29 -29
- package/src/interceptors/device-url.js +61 -61
- package/src/metrics.js +5 -5
- package/test/integration/spec/device.js +904 -904
- package/test/integration/spec/webex.js +42 -42
- package/test/unit/spec/device.js +409 -409
- package/test/unit/spec/features/feature-collection.js +24 -24
- package/test/unit/spec/features/feature-model.js +255 -255
- package/test/unit/spec/features/features-model.js +97 -97
- package/test/unit/spec/interceptors/device-url.js +215 -215
- package/test/unit/spec/wdm-dto.json +104 -104
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
// External dependencies.
|
|
2
|
-
import AmpCollection from 'ampersand-collection';
|
|
3
|
-
|
|
4
|
-
// Local Dependencies
|
|
5
|
-
import FeatureModel from './feature-model';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Feature collection model.
|
|
9
|
-
*
|
|
10
|
-
* @description
|
|
11
|
-
* This model contains a collection of features under a specific collection
|
|
12
|
-
* group.
|
|
13
|
-
*/
|
|
14
|
-
const FeatureCollection = AmpCollection.extend({
|
|
15
|
-
/**
|
|
16
|
-
* The unique identifier for the models in this collection.
|
|
17
|
-
*
|
|
18
|
-
* @type {string}
|
|
19
|
-
*/
|
|
20
|
-
mainIndex: 'key',
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* The type of model this collection can contain.
|
|
24
|
-
*
|
|
25
|
-
* @type {Class}
|
|
26
|
-
*/
|
|
27
|
-
model: FeatureModel,
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
export default FeatureCollection;
|
|
1
|
+
// External dependencies.
|
|
2
|
+
import AmpCollection from 'ampersand-collection';
|
|
3
|
+
|
|
4
|
+
// Local Dependencies
|
|
5
|
+
import FeatureModel from './feature-model';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Feature collection model.
|
|
9
|
+
*
|
|
10
|
+
* @description
|
|
11
|
+
* This model contains a collection of features under a specific collection
|
|
12
|
+
* group.
|
|
13
|
+
*/
|
|
14
|
+
const FeatureCollection = AmpCollection.extend({
|
|
15
|
+
/**
|
|
16
|
+
* The unique identifier for the models in this collection.
|
|
17
|
+
*
|
|
18
|
+
* @type {string}
|
|
19
|
+
*/
|
|
20
|
+
mainIndex: 'key',
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The type of model this collection can contain.
|
|
24
|
+
*
|
|
25
|
+
* @type {Class}
|
|
26
|
+
*/
|
|
27
|
+
model: FeatureModel,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export default FeatureCollection;
|
|
@@ -1,189 +1,189 @@
|
|
|
1
|
-
// External dependencies.
|
|
2
|
-
import AmpState from 'ampersand-state';
|
|
3
|
-
import {defaults, isObject} from 'lodash';
|
|
4
|
-
|
|
5
|
-
import {FEATURE_TYPES} from '../constants';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* The model returned from the {@link FeatureModel#parse} method.
|
|
9
|
-
*
|
|
10
|
-
* @typedef {Object} ParsedFeatureModel
|
|
11
|
-
* @property {boolean|number|string} ParsedFeatureModel.value - The parsed val.
|
|
12
|
-
* @property {string} ParsedFeatureModel.type - The type of the parsed val.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Feature model.
|
|
17
|
-
*
|
|
18
|
-
* @description
|
|
19
|
-
* This model contains details on a single feature and is received from the
|
|
20
|
-
* **WDM** service upon registration.
|
|
21
|
-
*/
|
|
22
|
-
const FeatureModel = AmpState.extend({
|
|
23
|
-
idAttribute: 'key', // needed by Ampersand to determine unique item
|
|
24
|
-
|
|
25
|
-
// Ampersand property members.
|
|
26
|
-
|
|
27
|
-
props: {
|
|
28
|
-
/**
|
|
29
|
-
* Contains the unique identifier for this feature to be addressed by.
|
|
30
|
-
*
|
|
31
|
-
* @type {string}
|
|
32
|
-
*/
|
|
33
|
-
key: 'string',
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* This property contains the date in which this feature was last modified.
|
|
37
|
-
*
|
|
38
|
-
* @type {date}
|
|
39
|
-
*/
|
|
40
|
-
lastModified: 'date',
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* This property defines whether or not the feature is mutable.
|
|
44
|
-
*
|
|
45
|
-
* @type {boolean}
|
|
46
|
-
*/
|
|
47
|
-
mutable: 'boolean',
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* This property contains the data type the string value should be
|
|
51
|
-
* interpreted as.
|
|
52
|
-
*
|
|
53
|
-
* @type {FEATURE_TYPES}
|
|
54
|
-
*/
|
|
55
|
-
type: 'string',
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* This property contains the string value of this feature.
|
|
59
|
-
*
|
|
60
|
-
* @type {string}
|
|
61
|
-
*/
|
|
62
|
-
val: 'string',
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* This property contains the interpreted value of this feature.
|
|
66
|
-
*
|
|
67
|
-
* @type {any}
|
|
68
|
-
*/
|
|
69
|
-
value: 'any',
|
|
70
|
-
},
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Class object constructor. This method safely initializes the class object
|
|
74
|
-
* prior to it fully loading to allow data to be accessed and modified
|
|
75
|
-
* immediately after construction instead of initialization.
|
|
76
|
-
*
|
|
77
|
-
* @override
|
|
78
|
-
* @param {Object} attrs - An object to map against the feature's properties.
|
|
79
|
-
* @param {Object} [options={}] - Ampersand options for `parse` and `parent`.
|
|
80
|
-
*/
|
|
81
|
-
constructor(attrs, options = {}) {
|
|
82
|
-
defaults(options, {parse: true});
|
|
83
|
-
|
|
84
|
-
return Reflect.apply(AmpState.prototype.constructor, this, [attrs, options]);
|
|
85
|
-
},
|
|
86
|
-
|
|
87
|
-
// Ampsersand method members.
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Parse {@link FeatureModel} properties recieved as strings from **WDM**
|
|
91
|
-
* and cast them as their appropriate types.
|
|
92
|
-
*
|
|
93
|
-
* @private
|
|
94
|
-
* @memberof FeatureModel
|
|
95
|
-
* @param {Object} model - The model to parse.
|
|
96
|
-
* @property {string} model.val - The value to be parsed.
|
|
97
|
-
* @returns {ParsedFeatureModel} - The parsed model.
|
|
98
|
-
*/
|
|
99
|
-
parse(model) {
|
|
100
|
-
// Validate that a model was provided and that it is an object.
|
|
101
|
-
if (!model || typeof model !== 'object') {
|
|
102
|
-
// Return an empty object to satisfy the requirements of `Ampersand`.
|
|
103
|
-
return {};
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const parsedModel = {...model};
|
|
107
|
-
const {val} = parsedModel;
|
|
108
|
-
|
|
109
|
-
// Validate that the value is a number.
|
|
110
|
-
if (!Number.isNaN(Number(val))) {
|
|
111
|
-
parsedModel.type = FEATURE_TYPES.NUMBER;
|
|
112
|
-
parsedModel.value = Number(val);
|
|
113
|
-
}
|
|
114
|
-
// Validate if the value should be a true boolean.
|
|
115
|
-
else if (typeof val === 'string' && val.toLowerCase() === 'true') {
|
|
116
|
-
parsedModel.type = FEATURE_TYPES.BOOLEAN;
|
|
117
|
-
parsedModel.value = true;
|
|
118
|
-
}
|
|
119
|
-
// Validate if the value should be a false boolean.
|
|
120
|
-
else if (typeof val === 'string' && val.toLowerCase() === 'false') {
|
|
121
|
-
parsedModel.type = FEATURE_TYPES.BOOLEAN;
|
|
122
|
-
parsedModel.value = false;
|
|
123
|
-
}
|
|
124
|
-
// In all other cases, the value is string, even if it is undefined.
|
|
125
|
-
else {
|
|
126
|
-
parsedModel.type = FEATURE_TYPES.STRING;
|
|
127
|
-
parsedModel.value = val;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
return parsedModel;
|
|
131
|
-
},
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Serialize the feature using the parent ampersand method with its date as an
|
|
135
|
-
* ISO string. This converts the feature into a request-transportable object.
|
|
136
|
-
*
|
|
137
|
-
* @override
|
|
138
|
-
* @param {Record<string,boolean>} [args] - List of properties to serialize.
|
|
139
|
-
* @returns {Object} - The request-ready transport object.
|
|
140
|
-
*/
|
|
141
|
-
serialize(...args) {
|
|
142
|
-
// Call the overloaded class member.
|
|
143
|
-
const attrs = Reflect.apply(AmpState.prototype.serialize, this, args);
|
|
144
|
-
|
|
145
|
-
// Validate that the overloaded class member returned an object with the
|
|
146
|
-
// `lastModified` key-value pair and instance it as an ISO string.
|
|
147
|
-
if (attrs.lastModified) {
|
|
148
|
-
attrs.lastModified = new Date(attrs.lastModified).toISOString();
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
return attrs;
|
|
152
|
-
},
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Set a property of this object to a specific value. This method utilizes
|
|
156
|
-
* code that exists within the `ampersand-state` dependency to handle
|
|
157
|
-
* scenarios in which `key = {"key": "value"}` or
|
|
158
|
-
* `key = "key", value = "value"`. Since the snippet is pulled directly from
|
|
159
|
-
* `ampersand-state`, there is no need to test both scenarios.
|
|
160
|
-
*
|
|
161
|
-
* @override
|
|
162
|
-
* @param {object | string} key - The key value, or object to be set.
|
|
163
|
-
* @param {any} value - The key value or object to set the keyed pair to.
|
|
164
|
-
* @param {any} options - The object to set the keyed pair to.
|
|
165
|
-
* @returns {any} - The changed property.
|
|
166
|
-
*/
|
|
167
|
-
set(key, value, options) {
|
|
168
|
-
// Declare formatted output variables for properly setting the targetted
|
|
169
|
-
// property for this method.
|
|
170
|
-
let attrs;
|
|
171
|
-
let optns;
|
|
172
|
-
|
|
173
|
-
// Validate if the key is an instance of any object or not.
|
|
174
|
-
if (isObject(key) || key === null) {
|
|
175
|
-
attrs = key;
|
|
176
|
-
optns = value;
|
|
177
|
-
} else {
|
|
178
|
-
attrs = {};
|
|
179
|
-
attrs[key] = value;
|
|
180
|
-
optns = options;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
attrs = this.parse(attrs, optns);
|
|
184
|
-
|
|
185
|
-
return Reflect.apply(AmpState.prototype.set, this, [attrs, optns]);
|
|
186
|
-
},
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
export default FeatureModel;
|
|
1
|
+
// External dependencies.
|
|
2
|
+
import AmpState from 'ampersand-state';
|
|
3
|
+
import {defaults, isObject} from 'lodash';
|
|
4
|
+
|
|
5
|
+
import {FEATURE_TYPES} from '../constants';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The model returned from the {@link FeatureModel#parse} method.
|
|
9
|
+
*
|
|
10
|
+
* @typedef {Object} ParsedFeatureModel
|
|
11
|
+
* @property {boolean|number|string} ParsedFeatureModel.value - The parsed val.
|
|
12
|
+
* @property {string} ParsedFeatureModel.type - The type of the parsed val.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Feature model.
|
|
17
|
+
*
|
|
18
|
+
* @description
|
|
19
|
+
* This model contains details on a single feature and is received from the
|
|
20
|
+
* **WDM** service upon registration.
|
|
21
|
+
*/
|
|
22
|
+
const FeatureModel = AmpState.extend({
|
|
23
|
+
idAttribute: 'key', // needed by Ampersand to determine unique item
|
|
24
|
+
|
|
25
|
+
// Ampersand property members.
|
|
26
|
+
|
|
27
|
+
props: {
|
|
28
|
+
/**
|
|
29
|
+
* Contains the unique identifier for this feature to be addressed by.
|
|
30
|
+
*
|
|
31
|
+
* @type {string}
|
|
32
|
+
*/
|
|
33
|
+
key: 'string',
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* This property contains the date in which this feature was last modified.
|
|
37
|
+
*
|
|
38
|
+
* @type {date}
|
|
39
|
+
*/
|
|
40
|
+
lastModified: 'date',
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* This property defines whether or not the feature is mutable.
|
|
44
|
+
*
|
|
45
|
+
* @type {boolean}
|
|
46
|
+
*/
|
|
47
|
+
mutable: 'boolean',
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* This property contains the data type the string value should be
|
|
51
|
+
* interpreted as.
|
|
52
|
+
*
|
|
53
|
+
* @type {FEATURE_TYPES}
|
|
54
|
+
*/
|
|
55
|
+
type: 'string',
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* This property contains the string value of this feature.
|
|
59
|
+
*
|
|
60
|
+
* @type {string}
|
|
61
|
+
*/
|
|
62
|
+
val: 'string',
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* This property contains the interpreted value of this feature.
|
|
66
|
+
*
|
|
67
|
+
* @type {any}
|
|
68
|
+
*/
|
|
69
|
+
value: 'any',
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Class object constructor. This method safely initializes the class object
|
|
74
|
+
* prior to it fully loading to allow data to be accessed and modified
|
|
75
|
+
* immediately after construction instead of initialization.
|
|
76
|
+
*
|
|
77
|
+
* @override
|
|
78
|
+
* @param {Object} attrs - An object to map against the feature's properties.
|
|
79
|
+
* @param {Object} [options={}] - Ampersand options for `parse` and `parent`.
|
|
80
|
+
*/
|
|
81
|
+
constructor(attrs, options = {}) {
|
|
82
|
+
defaults(options, {parse: true});
|
|
83
|
+
|
|
84
|
+
return Reflect.apply(AmpState.prototype.constructor, this, [attrs, options]);
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
// Ampsersand method members.
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Parse {@link FeatureModel} properties recieved as strings from **WDM**
|
|
91
|
+
* and cast them as their appropriate types.
|
|
92
|
+
*
|
|
93
|
+
* @private
|
|
94
|
+
* @memberof FeatureModel
|
|
95
|
+
* @param {Object} model - The model to parse.
|
|
96
|
+
* @property {string} model.val - The value to be parsed.
|
|
97
|
+
* @returns {ParsedFeatureModel} - The parsed model.
|
|
98
|
+
*/
|
|
99
|
+
parse(model) {
|
|
100
|
+
// Validate that a model was provided and that it is an object.
|
|
101
|
+
if (!model || typeof model !== 'object') {
|
|
102
|
+
// Return an empty object to satisfy the requirements of `Ampersand`.
|
|
103
|
+
return {};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const parsedModel = {...model};
|
|
107
|
+
const {val} = parsedModel;
|
|
108
|
+
|
|
109
|
+
// Validate that the value is a number.
|
|
110
|
+
if (!Number.isNaN(Number(val))) {
|
|
111
|
+
parsedModel.type = FEATURE_TYPES.NUMBER;
|
|
112
|
+
parsedModel.value = Number(val);
|
|
113
|
+
}
|
|
114
|
+
// Validate if the value should be a true boolean.
|
|
115
|
+
else if (typeof val === 'string' && val.toLowerCase() === 'true') {
|
|
116
|
+
parsedModel.type = FEATURE_TYPES.BOOLEAN;
|
|
117
|
+
parsedModel.value = true;
|
|
118
|
+
}
|
|
119
|
+
// Validate if the value should be a false boolean.
|
|
120
|
+
else if (typeof val === 'string' && val.toLowerCase() === 'false') {
|
|
121
|
+
parsedModel.type = FEATURE_TYPES.BOOLEAN;
|
|
122
|
+
parsedModel.value = false;
|
|
123
|
+
}
|
|
124
|
+
// In all other cases, the value is string, even if it is undefined.
|
|
125
|
+
else {
|
|
126
|
+
parsedModel.type = FEATURE_TYPES.STRING;
|
|
127
|
+
parsedModel.value = val;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return parsedModel;
|
|
131
|
+
},
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Serialize the feature using the parent ampersand method with its date as an
|
|
135
|
+
* ISO string. This converts the feature into a request-transportable object.
|
|
136
|
+
*
|
|
137
|
+
* @override
|
|
138
|
+
* @param {Record<string,boolean>} [args] - List of properties to serialize.
|
|
139
|
+
* @returns {Object} - The request-ready transport object.
|
|
140
|
+
*/
|
|
141
|
+
serialize(...args) {
|
|
142
|
+
// Call the overloaded class member.
|
|
143
|
+
const attrs = Reflect.apply(AmpState.prototype.serialize, this, args);
|
|
144
|
+
|
|
145
|
+
// Validate that the overloaded class member returned an object with the
|
|
146
|
+
// `lastModified` key-value pair and instance it as an ISO string.
|
|
147
|
+
if (attrs.lastModified) {
|
|
148
|
+
attrs.lastModified = new Date(attrs.lastModified).toISOString();
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return attrs;
|
|
152
|
+
},
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Set a property of this object to a specific value. This method utilizes
|
|
156
|
+
* code that exists within the `ampersand-state` dependency to handle
|
|
157
|
+
* scenarios in which `key = {"key": "value"}` or
|
|
158
|
+
* `key = "key", value = "value"`. Since the snippet is pulled directly from
|
|
159
|
+
* `ampersand-state`, there is no need to test both scenarios.
|
|
160
|
+
*
|
|
161
|
+
* @override
|
|
162
|
+
* @param {object | string} key - The key value, or object to be set.
|
|
163
|
+
* @param {any} value - The key value or object to set the keyed pair to.
|
|
164
|
+
* @param {any} options - The object to set the keyed pair to.
|
|
165
|
+
* @returns {any} - The changed property.
|
|
166
|
+
*/
|
|
167
|
+
set(key, value, options) {
|
|
168
|
+
// Declare formatted output variables for properly setting the targetted
|
|
169
|
+
// property for this method.
|
|
170
|
+
let attrs;
|
|
171
|
+
let optns;
|
|
172
|
+
|
|
173
|
+
// Validate if the key is an instance of any object or not.
|
|
174
|
+
if (isObject(key) || key === null) {
|
|
175
|
+
attrs = key;
|
|
176
|
+
optns = value;
|
|
177
|
+
} else {
|
|
178
|
+
attrs = {};
|
|
179
|
+
attrs[key] = value;
|
|
180
|
+
optns = options;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
attrs = this.parse(attrs, optns);
|
|
184
|
+
|
|
185
|
+
return Reflect.apply(AmpState.prototype.set, this, [attrs, optns]);
|
|
186
|
+
},
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
export default FeatureModel;
|
|
@@ -1,96 +1,96 @@
|
|
|
1
|
-
// External dependencies.
|
|
2
|
-
import AmpState from 'ampersand-state';
|
|
3
|
-
|
|
4
|
-
// Local Dependencies
|
|
5
|
-
import {FEATURE_COLLECTION_NAMES} from '../constants';
|
|
6
|
-
|
|
7
|
-
import FeatureCollection from './feature-collection';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Feature collection parent container.
|
|
11
|
-
*
|
|
12
|
-
* @description
|
|
13
|
-
* This class contains all of the feature collection class objects to help
|
|
14
|
-
* organize the data retrieved from the **wdm** service on device registration.
|
|
15
|
-
*/
|
|
16
|
-
const FeaturesModel = AmpState.extend({
|
|
17
|
-
// Ampersand property members.
|
|
18
|
-
|
|
19
|
-
collections: {
|
|
20
|
-
/**
|
|
21
|
-
* This collection contains the developer feature collection.
|
|
22
|
-
*
|
|
23
|
-
* @type {FeatureCollection}
|
|
24
|
-
*/
|
|
25
|
-
developer: FeatureCollection,
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* This collection contains the entitlement feature collection.
|
|
29
|
-
*
|
|
30
|
-
* @type {FeatureCollection}
|
|
31
|
-
*/
|
|
32
|
-
entitlement: FeatureCollection,
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* This collection contains the user feature collection.
|
|
36
|
-
*
|
|
37
|
-
* @type {FeatureCollection}
|
|
38
|
-
*/
|
|
39
|
-
user: FeatureCollection,
|
|
40
|
-
},
|
|
41
|
-
|
|
42
|
-
// Helper method members.
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Recursively clear attributes, children, and collections.
|
|
46
|
-
*
|
|
47
|
-
* @param {Object} options - Attribute options to unset.
|
|
48
|
-
* @returns {this}
|
|
49
|
-
*/
|
|
50
|
-
clear(options) {
|
|
51
|
-
// Clear the ampersand attributes safely if there are any. This class should
|
|
52
|
-
// never have any attributes.
|
|
53
|
-
Object.keys(this.attributes).forEach((key) => {
|
|
54
|
-
this.unset(key, options);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
// Clear the ampersand children safely if there are any. This class should
|
|
58
|
-
// never have any children.
|
|
59
|
-
/* eslint-disable-next-line no-underscore-dangle */
|
|
60
|
-
Object.keys(this._children).forEach((key) => {
|
|
61
|
-
this[key].clear();
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
// Clear the ampersand collections safely.
|
|
65
|
-
/* eslint-disable-next-line no-underscore-dangle */
|
|
66
|
-
Object.keys(this._collections).forEach((key) => {
|
|
67
|
-
this[key].reset();
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
return this;
|
|
71
|
-
},
|
|
72
|
-
|
|
73
|
-
// Ampersand method members.
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Initializer method for FeatureModel class object.
|
|
77
|
-
*
|
|
78
|
-
* @override
|
|
79
|
-
* @returns {void}
|
|
80
|
-
*/
|
|
81
|
-
initialize() {
|
|
82
|
-
// Declare the collection event names.
|
|
83
|
-
const eventNames = ['change:value', 'add', 'remove'];
|
|
84
|
-
|
|
85
|
-
// Initialize collection event listeners.
|
|
86
|
-
eventNames.forEach((eventName) => {
|
|
87
|
-
FEATURE_COLLECTION_NAMES.forEach((collectionName) => {
|
|
88
|
-
this[collectionName].on(eventName, (model, options) => {
|
|
89
|
-
this.trigger(`change:${collectionName}`, this, this[collectionName], options);
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
},
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
export default FeaturesModel;
|
|
1
|
+
// External dependencies.
|
|
2
|
+
import AmpState from 'ampersand-state';
|
|
3
|
+
|
|
4
|
+
// Local Dependencies
|
|
5
|
+
import {FEATURE_COLLECTION_NAMES} from '../constants';
|
|
6
|
+
|
|
7
|
+
import FeatureCollection from './feature-collection';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Feature collection parent container.
|
|
11
|
+
*
|
|
12
|
+
* @description
|
|
13
|
+
* This class contains all of the feature collection class objects to help
|
|
14
|
+
* organize the data retrieved from the **wdm** service on device registration.
|
|
15
|
+
*/
|
|
16
|
+
const FeaturesModel = AmpState.extend({
|
|
17
|
+
// Ampersand property members.
|
|
18
|
+
|
|
19
|
+
collections: {
|
|
20
|
+
/**
|
|
21
|
+
* This collection contains the developer feature collection.
|
|
22
|
+
*
|
|
23
|
+
* @type {FeatureCollection}
|
|
24
|
+
*/
|
|
25
|
+
developer: FeatureCollection,
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* This collection contains the entitlement feature collection.
|
|
29
|
+
*
|
|
30
|
+
* @type {FeatureCollection}
|
|
31
|
+
*/
|
|
32
|
+
entitlement: FeatureCollection,
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* This collection contains the user feature collection.
|
|
36
|
+
*
|
|
37
|
+
* @type {FeatureCollection}
|
|
38
|
+
*/
|
|
39
|
+
user: FeatureCollection,
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
// Helper method members.
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Recursively clear attributes, children, and collections.
|
|
46
|
+
*
|
|
47
|
+
* @param {Object} options - Attribute options to unset.
|
|
48
|
+
* @returns {this}
|
|
49
|
+
*/
|
|
50
|
+
clear(options) {
|
|
51
|
+
// Clear the ampersand attributes safely if there are any. This class should
|
|
52
|
+
// never have any attributes.
|
|
53
|
+
Object.keys(this.attributes).forEach((key) => {
|
|
54
|
+
this.unset(key, options);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// Clear the ampersand children safely if there are any. This class should
|
|
58
|
+
// never have any children.
|
|
59
|
+
/* eslint-disable-next-line no-underscore-dangle */
|
|
60
|
+
Object.keys(this._children).forEach((key) => {
|
|
61
|
+
this[key].clear();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// Clear the ampersand collections safely.
|
|
65
|
+
/* eslint-disable-next-line no-underscore-dangle */
|
|
66
|
+
Object.keys(this._collections).forEach((key) => {
|
|
67
|
+
this[key].reset();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
return this;
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
// Ampersand method members.
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Initializer method for FeatureModel class object.
|
|
77
|
+
*
|
|
78
|
+
* @override
|
|
79
|
+
* @returns {void}
|
|
80
|
+
*/
|
|
81
|
+
initialize() {
|
|
82
|
+
// Declare the collection event names.
|
|
83
|
+
const eventNames = ['change:value', 'add', 'remove'];
|
|
84
|
+
|
|
85
|
+
// Initialize collection event listeners.
|
|
86
|
+
eventNames.forEach((eventName) => {
|
|
87
|
+
FEATURE_COLLECTION_NAMES.forEach((collectionName) => {
|
|
88
|
+
this[collectionName].on(eventName, (model, options) => {
|
|
89
|
+
this.trigger(`change:${collectionName}`, this, this[collectionName], options);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
export default FeaturesModel;
|
package/src/features/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import FeatureCollection from './feature-collection';
|
|
2
|
-
import FeatureModel from './feature-model';
|
|
3
|
-
import FeaturesModel from './features-model';
|
|
4
|
-
|
|
5
|
-
export {FeatureCollection, FeatureModel, FeaturesModel};
|
|
1
|
+
import FeatureCollection from './feature-collection';
|
|
2
|
+
import FeatureModel from './feature-model';
|
|
3
|
+
import FeaturesModel from './features-model';
|
|
4
|
+
|
|
5
|
+
export {FeatureCollection, FeatureModel, FeaturesModel};
|