@subiz/widget-v4 4.1.142 → 4.1.144
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/README.md +5 -1
- package/compiled_src/bot.js +1 -2
- package/compiled_src/call/call.js +1 -2
- package/compiled_src/chatbox/Event.js +1 -2
- package/compiled_src/chatbox/Widget.js +3 -4
- package/compiled_src/chatbox/main.js +1 -2
- package/compiled_src/contact/contact.js +1 -2
- package/compiled_src/form/FormPage.js +1 -2
- package/compiled_src/form/index.js +1 -2
- package/compiled_src/form.js +1 -2
- package/compiled_src/notif/notif.js +1 -2
- package/compiled_src/order/icon.js +1 -2
- package/compiled_src/order/index.js +1 -2
- package/compiled_src/order/order.js +1 -2
- package/compiled_src/plugin.js +1 -2
- package/compiled_src/popup/popup.js +1 -2
- package/compiled_src/store/store.js +1255 -0
- package/compiled_src/util/campaign.js +88 -0
- package/compiled_src/util/common.js +1294 -0
- package/compiled_src/util/common.test.js +496 -0
- package/compiled_src/util/extractor.test.js +299 -0
- package/compiled_src/util/gate.js +38 -0
- package/compiled_src/util/gate.test.js +18 -0
- package/compiled_src/util/index.js +19 -0
- package/compiled_src/util/mutex.js +31 -0
- package/compiled_src/util/op.js +55 -0
- package/compiled_src/util/pubsub.js +29 -0
- package/compiled_src/util/pubsub.test.js +35 -0
- package/dist/196d3465f26.278.js +1 -0
- package/dist/196d3465f26.339.js +1 -0
- package/dist/196d3465f26.app.js +1 -0
- package/dist/196d3465f26.form.html +1 -0
- package/dist/196d3465f26.form.js +1 -0
- package/dist/{1967c022bc1.index.html → 196d3465f26.index.html} +15 -1
- package/dist/{1967c022bc1.library.html → 196d3465f26.library.html} +15 -1
- package/dist/196d3465f26.library.js +1 -0
- package/dist/{1967c022bc1.preview.html → 196d3465f26.preview.html} +1 -1
- package/dist/196d3465f26.preview.js +1 -0
- package/dist/196d3465f26.webview.js +1 -0
- package/dist/278.js +81 -70
- package/dist/HASH +1 -1
- package/dist/assets/img/stars_v2.79cf728.png +0 -0
- package/dist/screenshoot.js +317 -118
- package/index.html +14 -0
- package/package.json +10 -10
- package/src/chatbox/Widget.js +2 -2
- package/src/store/store.js +1 -1
- package/dist/1967c022bc1.278.js +0 -1
- package/dist/1967c022bc1.app.js +0 -1
- package/dist/1967c022bc1.form.html +0 -1
- package/dist/1967c022bc1.form.js +0 -1
- package/dist/1967c022bc1.library.js +0 -1
- package/dist/1967c022bc1.preview.js +0 -1
- package/dist/1967c022bc1.webview.js +0 -1
- /package/dist/{1967c022bc1.127.js → 196d3465f26.127.js} +0 -0
- /package/dist/{1967c022bc1.132.js → 196d3465f26.132.js} +0 -0
- /package/dist/{1967c022bc1.185.js → 196d3465f26.185.js} +0 -0
- /package/dist/{1967c022bc1.27.js → 196d3465f26.27.js} +0 -0
- /package/dist/{1967c022bc1.459.js → 196d3465f26.459.js} +0 -0
- /package/dist/{1967c022bc1.490.js → 196d3465f26.490.js} +0 -0
- /package/dist/{1967c022bc1.74.js → 196d3465f26.74.js} +0 -0
- /package/dist/{1967c022bc1.997.js → 196d3465f26.997.js} +0 -0
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var test = require('tape');
|
|
4
|
+
var lo = require('lodash');
|
|
5
|
+
let {
|
|
6
|
+
extractEmails,
|
|
7
|
+
extractPhones,
|
|
8
|
+
extractLinks,
|
|
9
|
+
extractText,
|
|
10
|
+
extractEmojis,
|
|
11
|
+
maskEmojis
|
|
12
|
+
} = require('./extractor.js');
|
|
13
|
+
test('extract emails', t => {
|
|
14
|
+
var tcs = [{
|
|
15
|
+
text: 'email',
|
|
16
|
+
out: []
|
|
17
|
+
}, {
|
|
18
|
+
text: 'email cua toi la thanh@live.com va b@live.com',
|
|
19
|
+
out: [{
|
|
20
|
+
index: 17,
|
|
21
|
+
length: 14
|
|
22
|
+
}, {
|
|
23
|
+
index: 35,
|
|
24
|
+
length: 10
|
|
25
|
+
}]
|
|
26
|
+
}, {
|
|
27
|
+
text: 'email cua toi la :thanh@live.com',
|
|
28
|
+
out: [{
|
|
29
|
+
index: 18,
|
|
30
|
+
length: 14
|
|
31
|
+
}]
|
|
32
|
+
}, {
|
|
33
|
+
text: 'email cua toi la :thanh@live.com/',
|
|
34
|
+
out: [{
|
|
35
|
+
index: 18,
|
|
36
|
+
length: 14
|
|
37
|
+
}]
|
|
38
|
+
}];
|
|
39
|
+
tcs.map(tc => {
|
|
40
|
+
var out = extractEmails(tc.text);
|
|
41
|
+
var isequal = lo.isEqual(out, tc.out);
|
|
42
|
+
t.true(isequal);
|
|
43
|
+
});
|
|
44
|
+
t.end();
|
|
45
|
+
});
|
|
46
|
+
test('extract phones', t => {
|
|
47
|
+
var tcs = [{
|
|
48
|
+
text: '',
|
|
49
|
+
out: []
|
|
50
|
+
}, {
|
|
51
|
+
text: 'sdt cua toi la 01234.566.7 va 0245092485',
|
|
52
|
+
out: [{
|
|
53
|
+
index: 15,
|
|
54
|
+
length: 11
|
|
55
|
+
}, {
|
|
56
|
+
index: 30,
|
|
57
|
+
length: 10
|
|
58
|
+
}]
|
|
59
|
+
}, {
|
|
60
|
+
text: 'a 0974.06.2222',
|
|
61
|
+
out: [{
|
|
62
|
+
index: 2,
|
|
63
|
+
length: 12
|
|
64
|
+
}]
|
|
65
|
+
}, {
|
|
66
|
+
text: 'https://donghoduyanh.com/tissot/t-classic-quartz/tissot-classic-dream-t0334103605101-262-560-4335.html',
|
|
67
|
+
out: [{
|
|
68
|
+
index: 71,
|
|
69
|
+
length: 13
|
|
70
|
+
}, {
|
|
71
|
+
index: 85,
|
|
72
|
+
length: 12
|
|
73
|
+
}]
|
|
74
|
+
}];
|
|
75
|
+
tcs.map(tc => {
|
|
76
|
+
var out = extractPhones(tc.text);
|
|
77
|
+
var isequal = lo.isEqual(out, tc.out);
|
|
78
|
+
t.true(isequal);
|
|
79
|
+
});
|
|
80
|
+
t.end();
|
|
81
|
+
});
|
|
82
|
+
test('extract link', t => {
|
|
83
|
+
var tcs = [{
|
|
84
|
+
text: '',
|
|
85
|
+
out: []
|
|
86
|
+
}, {
|
|
87
|
+
text: 'vao https://subiz.com a',
|
|
88
|
+
out: [{
|
|
89
|
+
index: 4,
|
|
90
|
+
length: 17
|
|
91
|
+
}]
|
|
92
|
+
}, {
|
|
93
|
+
text: 'day htt://a.com',
|
|
94
|
+
out: [{
|
|
95
|
+
index: 10,
|
|
96
|
+
length: 5
|
|
97
|
+
}]
|
|
98
|
+
}, {
|
|
99
|
+
text: 'chao http://http.ne/22',
|
|
100
|
+
out: [{
|
|
101
|
+
index: 5,
|
|
102
|
+
length: 17
|
|
103
|
+
}]
|
|
104
|
+
}, {
|
|
105
|
+
text: 'chao google.com',
|
|
106
|
+
out: [{
|
|
107
|
+
index: 5,
|
|
108
|
+
length: 10
|
|
109
|
+
}]
|
|
110
|
+
}];
|
|
111
|
+
tcs.map(tc => {
|
|
112
|
+
var out = extractLinks(tc.text);
|
|
113
|
+
var isequal = lo.isEqual(out, tc.out);
|
|
114
|
+
t.true(isequal);
|
|
115
|
+
});
|
|
116
|
+
t.end();
|
|
117
|
+
});
|
|
118
|
+
test('extract emojis', t => {
|
|
119
|
+
var tcs = [{
|
|
120
|
+
text: 'xin chao :smiling:',
|
|
121
|
+
out: [{
|
|
122
|
+
index: 9,
|
|
123
|
+
length: 9
|
|
124
|
+
}]
|
|
125
|
+
}, {
|
|
126
|
+
text: 'xin chao :smiling: :angry:',
|
|
127
|
+
out: [{
|
|
128
|
+
index: 9,
|
|
129
|
+
length: 9
|
|
130
|
+
}, {
|
|
131
|
+
index: 19,
|
|
132
|
+
length: 7
|
|
133
|
+
}]
|
|
134
|
+
}, {
|
|
135
|
+
text: 'xin chao ::smiling:',
|
|
136
|
+
out: [{
|
|
137
|
+
index: 10,
|
|
138
|
+
length: 9
|
|
139
|
+
}]
|
|
140
|
+
}, {
|
|
141
|
+
text: 'xin chao :smil e:',
|
|
142
|
+
out: []
|
|
143
|
+
}, {
|
|
144
|
+
text: 'xin chao :smil e:',
|
|
145
|
+
out: []
|
|
146
|
+
}, {
|
|
147
|
+
text: 'xin chao :smil:smiling:',
|
|
148
|
+
out: [{
|
|
149
|
+
index: 14,
|
|
150
|
+
length: 9
|
|
151
|
+
}]
|
|
152
|
+
}];
|
|
153
|
+
tcs.map(tc => {
|
|
154
|
+
var out = extractEmojis(tc.text);
|
|
155
|
+
var isequal = lo.isEqual(out, tc.out);
|
|
156
|
+
t.true(isequal);
|
|
157
|
+
});
|
|
158
|
+
t.end();
|
|
159
|
+
});
|
|
160
|
+
test('extract text', t => {
|
|
161
|
+
var tcs = [{
|
|
162
|
+
text: 'xin chao',
|
|
163
|
+
out: [{
|
|
164
|
+
type: 'text',
|
|
165
|
+
text: 'xin chao'
|
|
166
|
+
}]
|
|
167
|
+
}, {
|
|
168
|
+
text: 'xin chao thanhpk@live.com',
|
|
169
|
+
out: [{
|
|
170
|
+
type: 'text',
|
|
171
|
+
text: 'xin chao '
|
|
172
|
+
}, {
|
|
173
|
+
type: 'email',
|
|
174
|
+
text: 'thanhpk@live.com'
|
|
175
|
+
}]
|
|
176
|
+
}, {
|
|
177
|
+
text: 'xin chao thanhpk-0365045844@live.com, sdt: 03650451844',
|
|
178
|
+
out: [{
|
|
179
|
+
type: 'text',
|
|
180
|
+
text: 'xin chao '
|
|
181
|
+
}, {
|
|
182
|
+
type: 'email',
|
|
183
|
+
text: 'thanhpk-0365045844@live.com'
|
|
184
|
+
}, {
|
|
185
|
+
type: 'text',
|
|
186
|
+
text: ', sdt: '
|
|
187
|
+
}, {
|
|
188
|
+
type: 'phone',
|
|
189
|
+
text: '03650451844'
|
|
190
|
+
}]
|
|
191
|
+
}, {
|
|
192
|
+
text: 'xin chao https://subiz.com, sdt: 03650451844',
|
|
193
|
+
out: [{
|
|
194
|
+
type: 'text',
|
|
195
|
+
text: 'xin chao '
|
|
196
|
+
}, {
|
|
197
|
+
type: 'link',
|
|
198
|
+
text: 'https://subiz.com'
|
|
199
|
+
}, {
|
|
200
|
+
type: 'text',
|
|
201
|
+
text: ', sdt: '
|
|
202
|
+
}, {
|
|
203
|
+
type: 'phone',
|
|
204
|
+
text: '03650451844'
|
|
205
|
+
}]
|
|
206
|
+
}, {
|
|
207
|
+
text: 'https://google.com he :smiling:, :ll:',
|
|
208
|
+
out: [{
|
|
209
|
+
type: 'link',
|
|
210
|
+
text: 'https://google.com'
|
|
211
|
+
}, {
|
|
212
|
+
type: 'text',
|
|
213
|
+
text: ' he '
|
|
214
|
+
}, {
|
|
215
|
+
type: 'emoji',
|
|
216
|
+
text: ':smiling:'
|
|
217
|
+
}, {
|
|
218
|
+
type: 'text',
|
|
219
|
+
text: ', :ll:'
|
|
220
|
+
}]
|
|
221
|
+
}, {
|
|
222
|
+
text: 'google.com/?a=5&b=6 he :smiling:, :ll:',
|
|
223
|
+
out: [{
|
|
224
|
+
type: 'link',
|
|
225
|
+
text: 'google.com/?a=5&b=6'
|
|
226
|
+
}, {
|
|
227
|
+
type: 'text',
|
|
228
|
+
text: ' he '
|
|
229
|
+
}, {
|
|
230
|
+
type: 'emoji',
|
|
231
|
+
text: ':smiling:'
|
|
232
|
+
}, {
|
|
233
|
+
type: 'text',
|
|
234
|
+
text: ', :ll:'
|
|
235
|
+
}]
|
|
236
|
+
}];
|
|
237
|
+
tcs.map(tc => {
|
|
238
|
+
var out = extractText(tc.text);
|
|
239
|
+
var isequal = lo.isEqual(out, tc.out);
|
|
240
|
+
t.true(isequal);
|
|
241
|
+
});
|
|
242
|
+
t.end();
|
|
243
|
+
});
|
|
244
|
+
test('mask emoji', t => {
|
|
245
|
+
var tcs = [{
|
|
246
|
+
text: 'xin chao :smiling:',
|
|
247
|
+
out: [{
|
|
248
|
+
type: 'text',
|
|
249
|
+
value: 'xin chao '
|
|
250
|
+
}, {
|
|
251
|
+
type: 'emoji',
|
|
252
|
+
value: ':smiling:'
|
|
253
|
+
}]
|
|
254
|
+
}, {
|
|
255
|
+
text: 'xin chao :smiling: :angry:',
|
|
256
|
+
out: [{
|
|
257
|
+
type: 'text',
|
|
258
|
+
value: 'xin chao '
|
|
259
|
+
}, {
|
|
260
|
+
type: 'emoji',
|
|
261
|
+
value: ':smiling:'
|
|
262
|
+
}, {
|
|
263
|
+
type: 'text',
|
|
264
|
+
value: ' '
|
|
265
|
+
}, {
|
|
266
|
+
type: 'emoji',
|
|
267
|
+
value: ':angry:'
|
|
268
|
+
}]
|
|
269
|
+
}, {
|
|
270
|
+
text: 'xin chao ::smiling:',
|
|
271
|
+
out: [{
|
|
272
|
+
type: 'text',
|
|
273
|
+
value: 'xin chao :'
|
|
274
|
+
}, {
|
|
275
|
+
type: 'emoji',
|
|
276
|
+
value: ':smiling:'
|
|
277
|
+
}]
|
|
278
|
+
}, {
|
|
279
|
+
text: 'xin chao :smil e:',
|
|
280
|
+
out: [{
|
|
281
|
+
type: 'text',
|
|
282
|
+
value: 'xin chao :smil e:'
|
|
283
|
+
}]
|
|
284
|
+
}, {
|
|
285
|
+
text: 'xin chao :smil:smiling:',
|
|
286
|
+
out: [{
|
|
287
|
+
type: 'text',
|
|
288
|
+
value: 'xin chao :smil'
|
|
289
|
+
}, {
|
|
290
|
+
type: 'emoji',
|
|
291
|
+
value: ':smiling:'
|
|
292
|
+
}]
|
|
293
|
+
}];
|
|
294
|
+
tcs.forEach(tc => {
|
|
295
|
+
var out = maskEmojis(tc.text);
|
|
296
|
+
t.equal(JSON.stringify(out), JSON.stringify(tc.out));
|
|
297
|
+
});
|
|
298
|
+
t.end();
|
|
299
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
class Gate {
|
|
8
|
+
constructor(isOpen) {
|
|
9
|
+
this.isOpen = isOpen === true;
|
|
10
|
+
this.cbs = [];
|
|
11
|
+
}
|
|
12
|
+
open() {
|
|
13
|
+
this.isOpen = true;
|
|
14
|
+
let newcbs = [];
|
|
15
|
+
this.cbs.forEach(cb => {
|
|
16
|
+
if (this.isOpen) cb();else newcbs.push(cb);
|
|
17
|
+
});
|
|
18
|
+
this.cbs = newcbs;
|
|
19
|
+
}
|
|
20
|
+
close() {
|
|
21
|
+
this.isOpen = false;
|
|
22
|
+
}
|
|
23
|
+
entry(cb, lock) {
|
|
24
|
+
if (this.isOpen) {
|
|
25
|
+
if (lock) this.isOpen = false;
|
|
26
|
+
cb && cb();
|
|
27
|
+
return Promise.resolve();
|
|
28
|
+
}
|
|
29
|
+
return new Promise(resolve => {
|
|
30
|
+
this.cbs.push(() => {
|
|
31
|
+
if (lock) this.isOpen = false;
|
|
32
|
+
cb && cb();
|
|
33
|
+
resolve();
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.default = Gate;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var test = require('tape');
|
|
4
|
+
var Gate = require('./gate.js');
|
|
5
|
+
test('gate', async t => {
|
|
6
|
+
var gate = new Gate();
|
|
7
|
+
var flip = 0;
|
|
8
|
+
setTimeout(function () {
|
|
9
|
+
flip = 1;
|
|
10
|
+
gate.open();
|
|
11
|
+
}, 1000);
|
|
12
|
+
await gate.entry();
|
|
13
|
+
t.equal(flip, 1);
|
|
14
|
+
await gate.entry();
|
|
15
|
+
await gate.entry();
|
|
16
|
+
t.equal(flip, 1);
|
|
17
|
+
t.end();
|
|
18
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var common = _interopRequireWildcard(require("./common.js"));
|
|
8
|
+
var campaign = _interopRequireWildcard(require("./campaign.js"));
|
|
9
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
10
|
+
var sb = {};
|
|
11
|
+
sb = Object.assign(sb, common);
|
|
12
|
+
sb.Gate = require('./gate.js').default;
|
|
13
|
+
sb.Mutex = require('./mutex.js').default;
|
|
14
|
+
var op = require('./op.js');
|
|
15
|
+
sb.get = op.get;
|
|
16
|
+
sb.set = op.set;
|
|
17
|
+
sb.Pubsub = require('./pubsub.js').default;
|
|
18
|
+
sb = Object.assign(sb, campaign);
|
|
19
|
+
var _default = exports.default = sb;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
class Mutex {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.isOpen = true;
|
|
10
|
+
this.cbs = [];
|
|
11
|
+
}
|
|
12
|
+
_check() {
|
|
13
|
+
if (!this.isOpen) return;
|
|
14
|
+
let cb = this.cbs.pop();
|
|
15
|
+
if (!cb) return;
|
|
16
|
+
this.isOpen = false;
|
|
17
|
+
cb();
|
|
18
|
+
}
|
|
19
|
+
lock() {
|
|
20
|
+
return new Promise(resolve => {
|
|
21
|
+
this.cbs.push(resolve);
|
|
22
|
+
this._check();
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
unlock() {
|
|
26
|
+
if (this.isOpen) return;
|
|
27
|
+
this.isOpen = true;
|
|
28
|
+
this._check();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.default = Mutex;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.get = get;
|
|
7
|
+
exports.set = set;
|
|
8
|
+
var toStr = Object.prototype.toString;
|
|
9
|
+
var isArray = Array.isArray || function (obj) {
|
|
10
|
+
return toStr.call(obj) === '[object Array]';
|
|
11
|
+
};
|
|
12
|
+
function hasOwnProperty(obj, prop) {
|
|
13
|
+
if (obj == null) return false;
|
|
14
|
+
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
15
|
+
}
|
|
16
|
+
function getKey(key) {
|
|
17
|
+
var intKey = parseInt(key);
|
|
18
|
+
return intKey.toString() === key ? intKey : key;
|
|
19
|
+
}
|
|
20
|
+
function hasShallowProperty(obj, prop) {
|
|
21
|
+
return typeof prop === 'number' && isArray(obj) || hasOwnProperty(obj, prop);
|
|
22
|
+
}
|
|
23
|
+
function getShallowProperty(obj, prop) {
|
|
24
|
+
if (hasShallowProperty(obj, prop)) return obj[prop];
|
|
25
|
+
}
|
|
26
|
+
function get(obj, path, defaultValue) {
|
|
27
|
+
if (typeof path === 'number') path = [path];
|
|
28
|
+
if (!path || path.length === 0) return obj;
|
|
29
|
+
if (obj == null) return defaultValue;
|
|
30
|
+
if (typeof path === 'string') {
|
|
31
|
+
return get(obj, path.split('.'), defaultValue);
|
|
32
|
+
}
|
|
33
|
+
var currentPath = getKey(path[0]);
|
|
34
|
+
var nextObj = getShallowProperty(obj, currentPath);
|
|
35
|
+
if (nextObj === void 0) return defaultValue;
|
|
36
|
+
if (path.length === 1) return nextObj;
|
|
37
|
+
return get(obj[currentPath], path.slice(1), defaultValue);
|
|
38
|
+
}
|
|
39
|
+
function set(obj, path, value) {
|
|
40
|
+
if (typeof path === 'number') path = [path];
|
|
41
|
+
if (!path || path.length === 0) return obj;
|
|
42
|
+
if (typeof path === 'string') {
|
|
43
|
+
return set(obj, path.split('.').map(getKey), value);
|
|
44
|
+
}
|
|
45
|
+
var currentPath = path[0];
|
|
46
|
+
var currentValue = getShallowProperty(obj, currentPath);
|
|
47
|
+
if (path.length === 1) {
|
|
48
|
+
obj[currentPath] = value;
|
|
49
|
+
return currentValue;
|
|
50
|
+
}
|
|
51
|
+
if (currentValue === void 0) {
|
|
52
|
+
obj[currentPath] = typeof path[1] === 'number' ? [] : {};
|
|
53
|
+
}
|
|
54
|
+
return set(obj[currentPath], path.slice(1), value);
|
|
55
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var {
|
|
8
|
+
filter,
|
|
9
|
+
map
|
|
10
|
+
} = require('./common.js');
|
|
11
|
+
class Pubsub {
|
|
12
|
+
constructor() {
|
|
13
|
+
this.listeners = {};
|
|
14
|
+
}
|
|
15
|
+
publish(topic, payload, payload2, payload3) {
|
|
16
|
+
this.listeners[topic] = filter(this.listeners[topic], sub => sub.obj._isMounted);
|
|
17
|
+
map(this.listeners[topic], ({
|
|
18
|
+
cb
|
|
19
|
+
}) => cb(payload, payload2, payload3));
|
|
20
|
+
}
|
|
21
|
+
on2(obj, topic, cb) {
|
|
22
|
+
if (!this.listeners[topic]) this.listeners[topic] = [];
|
|
23
|
+
this.listeners[topic].push({
|
|
24
|
+
obj,
|
|
25
|
+
cb
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.default = Pubsub;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var test = require('tape');
|
|
4
|
+
var Pubsub = require('./pubsub.js');
|
|
5
|
+
test('pubsub simple', t => {
|
|
6
|
+
var ps = new Pubsub();
|
|
7
|
+
var msg = {
|
|
8
|
+
name: 'thanh'
|
|
9
|
+
};
|
|
10
|
+
var count = 0;
|
|
11
|
+
ps.on('hi', payload => {
|
|
12
|
+
t.equal(payload, msg);
|
|
13
|
+
count++;
|
|
14
|
+
});
|
|
15
|
+
ps.on('hi', payload => {
|
|
16
|
+
t.equal(payload, msg);
|
|
17
|
+
count++;
|
|
18
|
+
});
|
|
19
|
+
var sub = ps.on('hi', payload => {
|
|
20
|
+
t.equal(payload, msg);
|
|
21
|
+
count++;
|
|
22
|
+
});
|
|
23
|
+
ps.publish('hi', msg);
|
|
24
|
+
t.equal(count, 3);
|
|
25
|
+
ps.un(sub);
|
|
26
|
+
ps.publish('hi', msg);
|
|
27
|
+
ps.publish('hi', msg);
|
|
28
|
+
t.equal(count, 7);
|
|
29
|
+
ps.only('hi', payload => {
|
|
30
|
+
count--;
|
|
31
|
+
});
|
|
32
|
+
ps.publish('hi', 0);
|
|
33
|
+
t.equal(count, 6);
|
|
34
|
+
t.end();
|
|
35
|
+
});
|