@webex/common 2.59.1 → 2.59.3-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 +42 -42
- package/babel.config.js +3 -3
- package/dist/base64.js +22 -22
- package/dist/base64.js.map +1 -1
- package/dist/browser-detection.js.map +1 -1
- package/dist/capped-debounce.js +12 -12
- package/dist/capped-debounce.js.map +1 -1
- package/dist/check-required.js +8 -8
- package/dist/check-required.js.map +1 -1
- package/dist/constants.js.map +1 -1
- package/dist/defer.js +13 -13
- package/dist/defer.js.map +1 -1
- package/dist/deprecated.js +5 -5
- package/dist/deprecated.js.map +1 -1
- package/dist/event-envelope.js +11 -11
- package/dist/event-envelope.js.map +1 -1
- package/dist/events.js +15 -15
- package/dist/events.js.map +1 -1
- package/dist/exception.js +13 -13
- package/dist/exception.js.map +1 -1
- package/dist/in-browser/browser.js +2 -2
- package/dist/in-browser/browser.js.map +1 -1
- package/dist/in-browser/index.js.map +1 -1
- package/dist/in-browser/node.js +2 -2
- package/dist/in-browser/node.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/isBuffer.js +6 -6
- package/dist/isBuffer.js.map +1 -1
- package/dist/make-state-datatype.js +14 -14
- package/dist/make-state-datatype.js.map +1 -1
- package/dist/one-flight.js +13 -13
- package/dist/one-flight.js.map +1 -1
- package/dist/patterns.js +30 -30
- package/dist/patterns.js.map +1 -1
- package/dist/resolve-with.js +19 -19
- package/dist/resolve-with.js.map +1 -1
- package/dist/retry.js +17 -17
- package/dist/retry.js.map +1 -1
- package/dist/tap.js +14 -14
- package/dist/tap.js.map +1 -1
- package/dist/template-container.js +51 -51
- package/dist/template-container.js.map +1 -1
- package/dist/uuid-utils.js +76 -76
- package/dist/uuid-utils.js.map +1 -1
- package/dist/while-in-flight.js +5 -5
- package/dist/while-in-flight.js.map +1 -1
- package/jest.config.js +3 -3
- package/package.json +12 -11
- package/process +1 -1
- package/src/base64.js +67 -67
- package/src/browser-detection.js +37 -37
- package/src/capped-debounce.js +65 -65
- package/src/check-required.js +18 -18
- package/src/constants.js +79 -79
- package/src/defer.js +24 -24
- package/src/deprecated.js +19 -19
- package/src/event-envelope.js +54 -54
- package/src/events.js +55 -55
- package/src/exception.js +45 -45
- package/src/in-browser/browser.js +5 -5
- package/src/in-browser/index.js +11 -11
- package/src/in-browser/node.js +5 -5
- package/src/index.js +44 -44
- package/src/isBuffer.js +12 -12
- package/src/make-state-datatype.js +91 -91
- package/src/one-flight.js +89 -89
- package/src/patterns.js +51 -51
- package/src/resolve-with.js +27 -27
- package/src/retry.js +124 -124
- package/src/tap.js +25 -25
- package/src/template-container.js +222 -222
- package/src/uuid-utils.js +189 -189
- package/src/while-in-flight.js +38 -38
- package/test/unit/spec/capped-debounce.js +103 -103
- package/test/unit/spec/common.js +42 -42
- package/test/unit/spec/exception.js +102 -102
- package/test/unit/spec/one-flight.js +211 -211
- package/test/unit/spec/template-container.js +81 -81
- package/test/unit/spec/while-in-flight.js +70 -70
|
@@ -1,211 +1,211 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import AmpState from 'ampersand-state';
|
|
6
|
-
import {makeStateDataType, oneFlight} from '@webex/common';
|
|
7
|
-
import sinon from 'sinon';
|
|
8
|
-
import {assert} from '@webex/test-helper-chai';
|
|
9
|
-
|
|
10
|
-
describe('common', () => {
|
|
11
|
-
describe('@oneFlight', () => {
|
|
12
|
-
it('returns new promise on different function with undefined keyFactory', () => {
|
|
13
|
-
const C = AmpState.extend({
|
|
14
|
-
@oneFlight({keyFactory: (param1) => param1})
|
|
15
|
-
funcC1(param1) {
|
|
16
|
-
return new Promise((resolve) => {
|
|
17
|
-
process.nextTick(() => {
|
|
18
|
-
this.spy();
|
|
19
|
-
resolve(param1);
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
},
|
|
23
|
-
|
|
24
|
-
@oneFlight({keyFactory: (param2) => param2})
|
|
25
|
-
funcC2(param2) {
|
|
26
|
-
return new Promise((resolve) => {
|
|
27
|
-
this.spy();
|
|
28
|
-
resolve(param2);
|
|
29
|
-
});
|
|
30
|
-
},
|
|
31
|
-
|
|
32
|
-
spy() {
|
|
33
|
-
return true;
|
|
34
|
-
},
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
const c = new C();
|
|
38
|
-
|
|
39
|
-
sinon.spy(c, 'spy');
|
|
40
|
-
|
|
41
|
-
return Promise.all([c.funcC1(), c.funcC2()]).then(() => {
|
|
42
|
-
assert.calledTwice(c.spy);
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('returns existing promise on a function called twice with undefined keyFactory', () => {
|
|
47
|
-
const C = AmpState.extend({
|
|
48
|
-
@oneFlight({keyFactory: (param1) => param1})
|
|
49
|
-
funcC1(param1) {
|
|
50
|
-
return new Promise((resolve) => {
|
|
51
|
-
process.nextTick(() => {
|
|
52
|
-
this.spy();
|
|
53
|
-
resolve(param1);
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
},
|
|
57
|
-
|
|
58
|
-
spy() {
|
|
59
|
-
return true;
|
|
60
|
-
},
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
const c = new C();
|
|
64
|
-
|
|
65
|
-
sinon.spy(c, 'spy');
|
|
66
|
-
|
|
67
|
-
return Promise.all([c.funcC1(), c.funcC1()]).then(() => {
|
|
68
|
-
assert.calledOnce(c.spy);
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('ensures a given function may only be invoked once until completion', () => {
|
|
73
|
-
const C = AmpState.extend({
|
|
74
|
-
@oneFlight
|
|
75
|
-
funcC() {
|
|
76
|
-
return new Promise((resolve) => {
|
|
77
|
-
process.nextTick(() => {
|
|
78
|
-
this.spy();
|
|
79
|
-
resolve();
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
},
|
|
83
|
-
|
|
84
|
-
spy: sinon.spy(),
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
const c = new C();
|
|
88
|
-
|
|
89
|
-
return Promise.all([c.funcC(), c.funcC()]).then(() => assert.calledOnce(c.spy));
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it('handles complex event scenarios', () => {
|
|
93
|
-
// This is an attempt to simulate a bug encountered by the webex web
|
|
94
|
-
// client that has been, so far, difficult to reproduce in a controlled
|
|
95
|
-
// environment
|
|
96
|
-
|
|
97
|
-
// supertoken
|
|
98
|
-
const D = AmpState.extend({
|
|
99
|
-
props: {
|
|
100
|
-
d1: 'number',
|
|
101
|
-
},
|
|
102
|
-
|
|
103
|
-
funcD() {
|
|
104
|
-
return new Promise((resolve) => {
|
|
105
|
-
process.nextTick(() => {
|
|
106
|
-
resolve(new D());
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
},
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
// authorization
|
|
113
|
-
const C = AmpState.extend({
|
|
114
|
-
dataTypes: {
|
|
115
|
-
d: makeStateDataType(D, 'd').dataType,
|
|
116
|
-
},
|
|
117
|
-
|
|
118
|
-
props: {
|
|
119
|
-
d: makeStateDataType(D, 'd').prop,
|
|
120
|
-
},
|
|
121
|
-
|
|
122
|
-
@oneFlight
|
|
123
|
-
funcC() {
|
|
124
|
-
return new Promise((resolve) => {
|
|
125
|
-
const {d} = this;
|
|
126
|
-
|
|
127
|
-
this.unset(['d1', 'd2', 'd3']);
|
|
128
|
-
this.spy();
|
|
129
|
-
resolve(
|
|
130
|
-
d
|
|
131
|
-
.funcD()
|
|
132
|
-
.then((dd) => {
|
|
133
|
-
this.set('d1', dd);
|
|
134
|
-
|
|
135
|
-
return Promise.all([dd.funcD(), dd.funcD()]);
|
|
136
|
-
})
|
|
137
|
-
.then(([dd2, dd3]) => {
|
|
138
|
-
this.set({
|
|
139
|
-
d2: dd2,
|
|
140
|
-
d3: dd3,
|
|
141
|
-
});
|
|
142
|
-
})
|
|
143
|
-
);
|
|
144
|
-
});
|
|
145
|
-
},
|
|
146
|
-
|
|
147
|
-
spy: sinon.spy(),
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
// credentials
|
|
151
|
-
const B = AmpState.extend({
|
|
152
|
-
dataTypes: {
|
|
153
|
-
c: makeStateDataType(C, 'c').dataType,
|
|
154
|
-
},
|
|
155
|
-
|
|
156
|
-
props: {
|
|
157
|
-
c: makeStateDataType(C, 'c').prop,
|
|
158
|
-
},
|
|
159
|
-
|
|
160
|
-
@oneFlight
|
|
161
|
-
funcB1() {
|
|
162
|
-
return new Promise((resolve) => {
|
|
163
|
-
process.nextTick(() => resolve(this.funcB2()));
|
|
164
|
-
});
|
|
165
|
-
},
|
|
166
|
-
|
|
167
|
-
@oneFlight
|
|
168
|
-
funcB2() {
|
|
169
|
-
return new Promise((resolve) => {
|
|
170
|
-
process.nextTick(() => resolve(this.c.funcC()));
|
|
171
|
-
});
|
|
172
|
-
},
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
// webex
|
|
176
|
-
const A = AmpState.extend({
|
|
177
|
-
dataTypes: {
|
|
178
|
-
b: makeStateDataType(B, 'b').dataType,
|
|
179
|
-
},
|
|
180
|
-
|
|
181
|
-
props: {
|
|
182
|
-
b: makeStateDataType(B, 'b').prop,
|
|
183
|
-
},
|
|
184
|
-
|
|
185
|
-
@oneFlight
|
|
186
|
-
funcA() {
|
|
187
|
-
return this.b.funcB1();
|
|
188
|
-
},
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
const d = new D();
|
|
192
|
-
const c = new C({d});
|
|
193
|
-
const b = new B({c});
|
|
194
|
-
const a = new A({b});
|
|
195
|
-
|
|
196
|
-
// propagate change events
|
|
197
|
-
a.listenTo(a.b, 'change', (name, ...args) => {
|
|
198
|
-
args.unshift('change:b');
|
|
199
|
-
Reflect.apply(a.trigger, a, args);
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
a.listenTo(a, 'change:b', () => a.b.funcB1());
|
|
203
|
-
a.funcA();
|
|
204
|
-
a.b.c.d.d1 = 2;
|
|
205
|
-
|
|
206
|
-
return new Promise((resolve) => {
|
|
207
|
-
setTimeout(resolve, 500);
|
|
208
|
-
}).then(() => assert.calledOnce(a.b.c.spy));
|
|
209
|
-
});
|
|
210
|
-
});
|
|
211
|
-
});
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import AmpState from 'ampersand-state';
|
|
6
|
+
import {makeStateDataType, oneFlight} from '@webex/common';
|
|
7
|
+
import sinon from 'sinon';
|
|
8
|
+
import {assert} from '@webex/test-helper-chai';
|
|
9
|
+
|
|
10
|
+
describe('common', () => {
|
|
11
|
+
describe('@oneFlight', () => {
|
|
12
|
+
it('returns new promise on different function with undefined keyFactory', () => {
|
|
13
|
+
const C = AmpState.extend({
|
|
14
|
+
@oneFlight({keyFactory: (param1) => param1})
|
|
15
|
+
funcC1(param1) {
|
|
16
|
+
return new Promise((resolve) => {
|
|
17
|
+
process.nextTick(() => {
|
|
18
|
+
this.spy();
|
|
19
|
+
resolve(param1);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
@oneFlight({keyFactory: (param2) => param2})
|
|
25
|
+
funcC2(param2) {
|
|
26
|
+
return new Promise((resolve) => {
|
|
27
|
+
this.spy();
|
|
28
|
+
resolve(param2);
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
spy() {
|
|
33
|
+
return true;
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const c = new C();
|
|
38
|
+
|
|
39
|
+
sinon.spy(c, 'spy');
|
|
40
|
+
|
|
41
|
+
return Promise.all([c.funcC1(), c.funcC2()]).then(() => {
|
|
42
|
+
assert.calledTwice(c.spy);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('returns existing promise on a function called twice with undefined keyFactory', () => {
|
|
47
|
+
const C = AmpState.extend({
|
|
48
|
+
@oneFlight({keyFactory: (param1) => param1})
|
|
49
|
+
funcC1(param1) {
|
|
50
|
+
return new Promise((resolve) => {
|
|
51
|
+
process.nextTick(() => {
|
|
52
|
+
this.spy();
|
|
53
|
+
resolve(param1);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
spy() {
|
|
59
|
+
return true;
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const c = new C();
|
|
64
|
+
|
|
65
|
+
sinon.spy(c, 'spy');
|
|
66
|
+
|
|
67
|
+
return Promise.all([c.funcC1(), c.funcC1()]).then(() => {
|
|
68
|
+
assert.calledOnce(c.spy);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('ensures a given function may only be invoked once until completion', () => {
|
|
73
|
+
const C = AmpState.extend({
|
|
74
|
+
@oneFlight
|
|
75
|
+
funcC() {
|
|
76
|
+
return new Promise((resolve) => {
|
|
77
|
+
process.nextTick(() => {
|
|
78
|
+
this.spy();
|
|
79
|
+
resolve();
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
spy: sinon.spy(),
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
const c = new C();
|
|
88
|
+
|
|
89
|
+
return Promise.all([c.funcC(), c.funcC()]).then(() => assert.calledOnce(c.spy));
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('handles complex event scenarios', () => {
|
|
93
|
+
// This is an attempt to simulate a bug encountered by the webex web
|
|
94
|
+
// client that has been, so far, difficult to reproduce in a controlled
|
|
95
|
+
// environment
|
|
96
|
+
|
|
97
|
+
// supertoken
|
|
98
|
+
const D = AmpState.extend({
|
|
99
|
+
props: {
|
|
100
|
+
d1: 'number',
|
|
101
|
+
},
|
|
102
|
+
|
|
103
|
+
funcD() {
|
|
104
|
+
return new Promise((resolve) => {
|
|
105
|
+
process.nextTick(() => {
|
|
106
|
+
resolve(new D());
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
// authorization
|
|
113
|
+
const C = AmpState.extend({
|
|
114
|
+
dataTypes: {
|
|
115
|
+
d: makeStateDataType(D, 'd').dataType,
|
|
116
|
+
},
|
|
117
|
+
|
|
118
|
+
props: {
|
|
119
|
+
d: makeStateDataType(D, 'd').prop,
|
|
120
|
+
},
|
|
121
|
+
|
|
122
|
+
@oneFlight
|
|
123
|
+
funcC() {
|
|
124
|
+
return new Promise((resolve) => {
|
|
125
|
+
const {d} = this;
|
|
126
|
+
|
|
127
|
+
this.unset(['d1', 'd2', 'd3']);
|
|
128
|
+
this.spy();
|
|
129
|
+
resolve(
|
|
130
|
+
d
|
|
131
|
+
.funcD()
|
|
132
|
+
.then((dd) => {
|
|
133
|
+
this.set('d1', dd);
|
|
134
|
+
|
|
135
|
+
return Promise.all([dd.funcD(), dd.funcD()]);
|
|
136
|
+
})
|
|
137
|
+
.then(([dd2, dd3]) => {
|
|
138
|
+
this.set({
|
|
139
|
+
d2: dd2,
|
|
140
|
+
d3: dd3,
|
|
141
|
+
});
|
|
142
|
+
})
|
|
143
|
+
);
|
|
144
|
+
});
|
|
145
|
+
},
|
|
146
|
+
|
|
147
|
+
spy: sinon.spy(),
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
// credentials
|
|
151
|
+
const B = AmpState.extend({
|
|
152
|
+
dataTypes: {
|
|
153
|
+
c: makeStateDataType(C, 'c').dataType,
|
|
154
|
+
},
|
|
155
|
+
|
|
156
|
+
props: {
|
|
157
|
+
c: makeStateDataType(C, 'c').prop,
|
|
158
|
+
},
|
|
159
|
+
|
|
160
|
+
@oneFlight
|
|
161
|
+
funcB1() {
|
|
162
|
+
return new Promise((resolve) => {
|
|
163
|
+
process.nextTick(() => resolve(this.funcB2()));
|
|
164
|
+
});
|
|
165
|
+
},
|
|
166
|
+
|
|
167
|
+
@oneFlight
|
|
168
|
+
funcB2() {
|
|
169
|
+
return new Promise((resolve) => {
|
|
170
|
+
process.nextTick(() => resolve(this.c.funcC()));
|
|
171
|
+
});
|
|
172
|
+
},
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
// webex
|
|
176
|
+
const A = AmpState.extend({
|
|
177
|
+
dataTypes: {
|
|
178
|
+
b: makeStateDataType(B, 'b').dataType,
|
|
179
|
+
},
|
|
180
|
+
|
|
181
|
+
props: {
|
|
182
|
+
b: makeStateDataType(B, 'b').prop,
|
|
183
|
+
},
|
|
184
|
+
|
|
185
|
+
@oneFlight
|
|
186
|
+
funcA() {
|
|
187
|
+
return this.b.funcB1();
|
|
188
|
+
},
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
const d = new D();
|
|
192
|
+
const c = new C({d});
|
|
193
|
+
const b = new B({c});
|
|
194
|
+
const a = new A({b});
|
|
195
|
+
|
|
196
|
+
// propagate change events
|
|
197
|
+
a.listenTo(a.b, 'change', (name, ...args) => {
|
|
198
|
+
args.unshift('change:b');
|
|
199
|
+
Reflect.apply(a.trigger, a, args);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
a.listenTo(a, 'change:b', () => a.b.funcB1());
|
|
203
|
+
a.funcA();
|
|
204
|
+
a.b.c.d.d1 = 2;
|
|
205
|
+
|
|
206
|
+
return new Promise((resolve) => {
|
|
207
|
+
setTimeout(resolve, 500);
|
|
208
|
+
}).then(() => assert.calledOnce(a.b.c.spy));
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
});
|
|
@@ -1,81 +1,81 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import {assert} from '@webex/test-helper-chai';
|
|
6
|
-
import {make} from '@webex/common';
|
|
7
|
-
|
|
8
|
-
describe('common', () => {
|
|
9
|
-
describe('TemplateContainer', () => {
|
|
10
|
-
describe('make()', () => {
|
|
11
|
-
// _.memoize breaks most of the tests; since `make` only gets used a
|
|
12
|
-
// handful of times, I'm not that worried about duplicate container
|
|
13
|
-
// definitions.
|
|
14
|
-
it.skip('is memoized', () => {
|
|
15
|
-
const WeakKeyedMap = make(WeakMap, Map);
|
|
16
|
-
const WeakKeyedMap2 = make(WeakMap, Map);
|
|
17
|
-
|
|
18
|
-
assert.equal(WeakKeyedMap2, WeakKeyedMap);
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
describe('make(Map)', () => {
|
|
23
|
-
it('behaves like a map', () => {
|
|
24
|
-
const MadeMap = make(Map);
|
|
25
|
-
|
|
26
|
-
const key = {};
|
|
27
|
-
const value = 42;
|
|
28
|
-
|
|
29
|
-
const m = new MadeMap();
|
|
30
|
-
|
|
31
|
-
assert.isFalse(m.has(key));
|
|
32
|
-
m.set(key, value);
|
|
33
|
-
assert.equal(m.get(key), value);
|
|
34
|
-
assert.isTrue(m.has(key));
|
|
35
|
-
assert.isTrue(m.delete(key));
|
|
36
|
-
assert.isFalse(m.has(key));
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
describe('make(WeakMap, Map)', () => {
|
|
41
|
-
it('works', () => {
|
|
42
|
-
const WeakKeyedMap = make(WeakMap, Map);
|
|
43
|
-
|
|
44
|
-
class Base {}
|
|
45
|
-
const key = {};
|
|
46
|
-
const value = 42;
|
|
47
|
-
|
|
48
|
-
const b = new Base();
|
|
49
|
-
const w = new WeakKeyedMap();
|
|
50
|
-
|
|
51
|
-
assert.isFalse(w.has(b, key));
|
|
52
|
-
w.set(b, key, value);
|
|
53
|
-
assert.equal(w.get(b, key), value);
|
|
54
|
-
assert.isTrue(w.has(b, key));
|
|
55
|
-
assert.isTrue(w.delete(b, key));
|
|
56
|
-
assert.isFalse(w.has(b, key));
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
describe('make(Map, Map, Set)', () => {
|
|
61
|
-
it('works', () => {
|
|
62
|
-
const key1 = {};
|
|
63
|
-
const key2 = 'blarg';
|
|
64
|
-
const value = 42;
|
|
65
|
-
|
|
66
|
-
const M = Map;
|
|
67
|
-
const S = Set;
|
|
68
|
-
|
|
69
|
-
const Container = make(M, M, S);
|
|
70
|
-
const c = new Container();
|
|
71
|
-
|
|
72
|
-
assert.isFalse(c.has(key1, key2, value));
|
|
73
|
-
c.set(key1, key2, value);
|
|
74
|
-
assert.instanceOf(c.get(key1, key2), Set);
|
|
75
|
-
assert.isTrue(c.has(key1, key2, value));
|
|
76
|
-
assert.isTrue(c.delete(key1, key2, value));
|
|
77
|
-
assert.isFalse(c.has(key1, key2, value));
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
});
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {assert} from '@webex/test-helper-chai';
|
|
6
|
+
import {make} from '@webex/common';
|
|
7
|
+
|
|
8
|
+
describe('common', () => {
|
|
9
|
+
describe('TemplateContainer', () => {
|
|
10
|
+
describe('make()', () => {
|
|
11
|
+
// _.memoize breaks most of the tests; since `make` only gets used a
|
|
12
|
+
// handful of times, I'm not that worried about duplicate container
|
|
13
|
+
// definitions.
|
|
14
|
+
it.skip('is memoized', () => {
|
|
15
|
+
const WeakKeyedMap = make(WeakMap, Map);
|
|
16
|
+
const WeakKeyedMap2 = make(WeakMap, Map);
|
|
17
|
+
|
|
18
|
+
assert.equal(WeakKeyedMap2, WeakKeyedMap);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
describe('make(Map)', () => {
|
|
23
|
+
it('behaves like a map', () => {
|
|
24
|
+
const MadeMap = make(Map);
|
|
25
|
+
|
|
26
|
+
const key = {};
|
|
27
|
+
const value = 42;
|
|
28
|
+
|
|
29
|
+
const m = new MadeMap();
|
|
30
|
+
|
|
31
|
+
assert.isFalse(m.has(key));
|
|
32
|
+
m.set(key, value);
|
|
33
|
+
assert.equal(m.get(key), value);
|
|
34
|
+
assert.isTrue(m.has(key));
|
|
35
|
+
assert.isTrue(m.delete(key));
|
|
36
|
+
assert.isFalse(m.has(key));
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe('make(WeakMap, Map)', () => {
|
|
41
|
+
it('works', () => {
|
|
42
|
+
const WeakKeyedMap = make(WeakMap, Map);
|
|
43
|
+
|
|
44
|
+
class Base {}
|
|
45
|
+
const key = {};
|
|
46
|
+
const value = 42;
|
|
47
|
+
|
|
48
|
+
const b = new Base();
|
|
49
|
+
const w = new WeakKeyedMap();
|
|
50
|
+
|
|
51
|
+
assert.isFalse(w.has(b, key));
|
|
52
|
+
w.set(b, key, value);
|
|
53
|
+
assert.equal(w.get(b, key), value);
|
|
54
|
+
assert.isTrue(w.has(b, key));
|
|
55
|
+
assert.isTrue(w.delete(b, key));
|
|
56
|
+
assert.isFalse(w.has(b, key));
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
describe('make(Map, Map, Set)', () => {
|
|
61
|
+
it('works', () => {
|
|
62
|
+
const key1 = {};
|
|
63
|
+
const key2 = 'blarg';
|
|
64
|
+
const value = 42;
|
|
65
|
+
|
|
66
|
+
const M = Map;
|
|
67
|
+
const S = Set;
|
|
68
|
+
|
|
69
|
+
const Container = make(M, M, S);
|
|
70
|
+
const c = new Container();
|
|
71
|
+
|
|
72
|
+
assert.isFalse(c.has(key1, key2, value));
|
|
73
|
+
c.set(key1, key2, value);
|
|
74
|
+
assert.instanceOf(c.get(key1, key2), Set);
|
|
75
|
+
assert.isTrue(c.has(key1, key2, value));
|
|
76
|
+
assert.isTrue(c.delete(key1, key2, value));
|
|
77
|
+
assert.isFalse(c.has(key1, key2, value));
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
});
|