@player-ui/pubsub-plugin 0.8.0--canary.307.9621 → 0.8.0-next.2
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/dist/PubSubPlugin.native.js +479 -0
- package/dist/PubSubPlugin.native.js.map +1 -0
- package/dist/cjs/index.cjs +270 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/{index.cjs.js → index.legacy-esm.js} +97 -35
- package/dist/{index.esm.js → index.mjs} +97 -29
- package/dist/index.mjs.map +1 -0
- package/package.json +24 -61
- package/src/__test__/handler.test.ts +89 -0
- package/src/__test__/plugin.test.ts +163 -0
- package/src/__test__/pubsub.test.ts +309 -0
- package/src/handler.ts +5 -5
- package/src/index.ts +3 -3
- package/src/plugin.ts +11 -11
- package/src/pubsub.ts +9 -9
- package/src/symbols.ts +1 -1
- package/src/utils.ts +3 -3
- package/types/handler.d.ts +13 -0
- package/types/index.d.ts +4 -0
- package/types/plugin.d.ts +50 -0
- package/types/pubsub.d.ts +53 -0
- package/types/symbols.d.ts +2 -0
- package/types/utils.d.ts +7 -0
- package/dist/index.d.ts +0 -116
- package/dist/pubsub-plugin.dev.js +0 -289
- package/dist/pubsub-plugin.prod.js +0 -1
|
@@ -0,0 +1,479 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
function _array_like_to_array(arr, len) {
|
|
3
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
4
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
5
|
+
return arr2;
|
|
6
|
+
}
|
|
7
|
+
function _array_without_holes(arr) {
|
|
8
|
+
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
9
|
+
}
|
|
10
|
+
function _class_call_check(instance, Constructor) {
|
|
11
|
+
if (!(instance instanceof Constructor)) {
|
|
12
|
+
throw new TypeError("Cannot call a class as a function");
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function _defineProperties(target, props) {
|
|
16
|
+
for(var i = 0; i < props.length; i++){
|
|
17
|
+
var descriptor = props[i];
|
|
18
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
19
|
+
descriptor.configurable = true;
|
|
20
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
21
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
25
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
26
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
27
|
+
return Constructor;
|
|
28
|
+
}
|
|
29
|
+
function _iterable_to_array(iter) {
|
|
30
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
31
|
+
}
|
|
32
|
+
function _non_iterable_spread() {
|
|
33
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
34
|
+
}
|
|
35
|
+
function _to_consumable_array(arr) {
|
|
36
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
37
|
+
}
|
|
38
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
39
|
+
if (!o) return;
|
|
40
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
41
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
42
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
43
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
44
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
45
|
+
}
|
|
46
|
+
var PubSubPlugin = function() {
|
|
47
|
+
var splitEvent = // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/pubsub/core/src/pubsub.ts
|
|
48
|
+
function splitEvent(event) {
|
|
49
|
+
return event.split(".").reduce(function(prev, curr, index) {
|
|
50
|
+
if (index === 0) {
|
|
51
|
+
return [
|
|
52
|
+
curr
|
|
53
|
+
];
|
|
54
|
+
}
|
|
55
|
+
return _to_consumable_array(prev).concat([
|
|
56
|
+
"".concat(prev[index - 1], ".").concat(curr)
|
|
57
|
+
]);
|
|
58
|
+
}, []);
|
|
59
|
+
};
|
|
60
|
+
var getPubSubPlugin = // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/pubsub/core/src/utils.ts
|
|
61
|
+
function getPubSubPlugin(player) {
|
|
62
|
+
var existing = player.findPlugin(PubSubPluginSymbol);
|
|
63
|
+
var plugin = existing || new PubSubPlugin();
|
|
64
|
+
if (!existing) {
|
|
65
|
+
player.registerPlugin(plugin);
|
|
66
|
+
}
|
|
67
|
+
return plugin;
|
|
68
|
+
};
|
|
69
|
+
var __defProp = Object.defineProperty;
|
|
70
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
71
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
72
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
73
|
+
var __export = function(target, all) {
|
|
74
|
+
for(var name in all)__defProp(target, name, {
|
|
75
|
+
get: all[name],
|
|
76
|
+
enumerable: true
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
var __copyProps = function(to, from, except, desc) {
|
|
80
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
81
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
82
|
+
try {
|
|
83
|
+
var _loop = function() {
|
|
84
|
+
var key = _step.value;
|
|
85
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
86
|
+
get: function() {
|
|
87
|
+
return from[key];
|
|
88
|
+
},
|
|
89
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
for(var _iterator = __getOwnPropNames(from)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
|
|
93
|
+
} catch (err) {
|
|
94
|
+
_didIteratorError = true;
|
|
95
|
+
_iteratorError = err;
|
|
96
|
+
} finally{
|
|
97
|
+
try {
|
|
98
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
99
|
+
_iterator.return();
|
|
100
|
+
}
|
|
101
|
+
} finally{
|
|
102
|
+
if (_didIteratorError) {
|
|
103
|
+
throw _iteratorError;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return to;
|
|
109
|
+
};
|
|
110
|
+
var __toCommonJS = function(mod) {
|
|
111
|
+
return __copyProps(__defProp({}, "__esModule", {
|
|
112
|
+
value: true
|
|
113
|
+
}), mod);
|
|
114
|
+
};
|
|
115
|
+
// ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/pubsub/core/src/index.ts
|
|
116
|
+
var src_exports = {};
|
|
117
|
+
__export(src_exports, {
|
|
118
|
+
PubSubHandlerPlugin: function() {
|
|
119
|
+
return PubSubHandlerPlugin;
|
|
120
|
+
},
|
|
121
|
+
PubSubPlugin: function() {
|
|
122
|
+
return PubSubPlugin;
|
|
123
|
+
},
|
|
124
|
+
PubSubPluginSymbol: function() {
|
|
125
|
+
return PubSubPluginSymbol;
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
var count = 1;
|
|
129
|
+
var TinyPubSub = /*#__PURE__*/ function() {
|
|
130
|
+
function TinyPubSub() {
|
|
131
|
+
_class_call_check(this, TinyPubSub);
|
|
132
|
+
this.events = /* @__PURE__ */ new Map();
|
|
133
|
+
this.tokens = /* @__PURE__ */ new Map();
|
|
134
|
+
}
|
|
135
|
+
_create_class(TinyPubSub, [
|
|
136
|
+
{
|
|
137
|
+
/**
|
|
138
|
+
* Publish an event with any number of additional arguments
|
|
139
|
+
*/ key: "publish",
|
|
140
|
+
value: function publish(event) {
|
|
141
|
+
var _this = this;
|
|
142
|
+
for(var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
|
|
143
|
+
args[_key - 1] = arguments[_key];
|
|
144
|
+
}
|
|
145
|
+
if (typeof event !== "string") {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
if (event.includes(".")) {
|
|
149
|
+
var eventKeys = splitEvent(event);
|
|
150
|
+
eventKeys.forEach(function(key) {
|
|
151
|
+
_this.deliver.apply(_this, [
|
|
152
|
+
key,
|
|
153
|
+
event
|
|
154
|
+
].concat(_to_consumable_array(args)));
|
|
155
|
+
});
|
|
156
|
+
} else {
|
|
157
|
+
this.deliver.apply(this, [
|
|
158
|
+
event,
|
|
159
|
+
event
|
|
160
|
+
].concat(_to_consumable_array(args)));
|
|
161
|
+
}
|
|
162
|
+
this.deliver.apply(this, [
|
|
163
|
+
"*",
|
|
164
|
+
event
|
|
165
|
+
].concat(_to_consumable_array(args)));
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
/**
|
|
170
|
+
* Subscribe to an event
|
|
171
|
+
*
|
|
172
|
+
* Events are also heirarchical when separated by a period. Given the following:
|
|
173
|
+
*
|
|
174
|
+
* publish('a.b.c', 'one', 'two', 'three)
|
|
175
|
+
*
|
|
176
|
+
* The subscribe event will be called when the event is passed as 'a', 'a.b', or 'a.b.c'.
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* // subscribes to the top level 'a' publish
|
|
180
|
+
* subscribe('a', (event, ...args) => console.log(event, ...args))
|
|
181
|
+
*/ key: "subscribe",
|
|
182
|
+
value: function subscribe(event, handler) {
|
|
183
|
+
var uuid = "uuid_".concat(++count);
|
|
184
|
+
if (typeof event === "string") {
|
|
185
|
+
if (!this.events.has(event)) {
|
|
186
|
+
this.events.set(event, /* @__PURE__ */ new Map());
|
|
187
|
+
}
|
|
188
|
+
var handlers = this.events.get(event);
|
|
189
|
+
handlers.set(uuid, handler);
|
|
190
|
+
this.tokens.set(uuid, event);
|
|
191
|
+
}
|
|
192
|
+
return uuid;
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
/**
|
|
197
|
+
* Unsubscribes to a specific subscription given it's symbol or an entire
|
|
198
|
+
* event when passed as a string.
|
|
199
|
+
*
|
|
200
|
+
* When existing subscriptions exist for heirarchical events such as 'a.b.c',
|
|
201
|
+
* when passing an event 'a' to unsubscribe, all subscriptions for 'a', 'a.b',
|
|
202
|
+
* & 'a.b.c' will be unsubscribed as well.
|
|
203
|
+
*/ key: "unsubscribe",
|
|
204
|
+
value: function unsubscribe(value) {
|
|
205
|
+
if (typeof value === "string" && value.startsWith("uuid")) {
|
|
206
|
+
var path = this.tokens.get(value);
|
|
207
|
+
if (typeof path === "undefined") {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
var innerPath = this.events.get(path);
|
|
211
|
+
innerPath === null || innerPath === void 0 ? void 0 : innerPath.delete(value);
|
|
212
|
+
this.tokens.delete(value);
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
if (typeof value === "string") {
|
|
216
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
217
|
+
try {
|
|
218
|
+
for(var _iterator = this.events.keys()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
219
|
+
var key = _step.value;
|
|
220
|
+
if (key.indexOf(value) === 0) {
|
|
221
|
+
var tokens = this.events.get(key);
|
|
222
|
+
if (tokens && tokens.size) {
|
|
223
|
+
var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
|
|
224
|
+
try {
|
|
225
|
+
for(var _iterator1 = tokens.keys()[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
|
|
226
|
+
var token = _step1.value;
|
|
227
|
+
this.tokens.delete(token);
|
|
228
|
+
}
|
|
229
|
+
} catch (err) {
|
|
230
|
+
_didIteratorError1 = true;
|
|
231
|
+
_iteratorError1 = err;
|
|
232
|
+
} finally{
|
|
233
|
+
try {
|
|
234
|
+
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
235
|
+
_iterator1.return();
|
|
236
|
+
}
|
|
237
|
+
} finally{
|
|
238
|
+
if (_didIteratorError1) {
|
|
239
|
+
throw _iteratorError1;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
this.events.delete(key);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
} catch (err) {
|
|
248
|
+
_didIteratorError = true;
|
|
249
|
+
_iteratorError = err;
|
|
250
|
+
} finally{
|
|
251
|
+
try {
|
|
252
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
253
|
+
_iterator.return();
|
|
254
|
+
}
|
|
255
|
+
} finally{
|
|
256
|
+
if (_didIteratorError) {
|
|
257
|
+
throw _iteratorError;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
/**
|
|
266
|
+
* Get the number of subscriptions for a specific event, or when left blank
|
|
267
|
+
* will return the overall number of subscriptions for the entire pubsub.
|
|
268
|
+
*/ key: "count",
|
|
269
|
+
value: function count(event) {
|
|
270
|
+
var counter = 0;
|
|
271
|
+
if (typeof event === "undefined") {
|
|
272
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
273
|
+
try {
|
|
274
|
+
for(var _iterator = this.events.values()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
275
|
+
var handlers2 = _step.value;
|
|
276
|
+
counter += handlers2.size;
|
|
277
|
+
}
|
|
278
|
+
} catch (err) {
|
|
279
|
+
_didIteratorError = true;
|
|
280
|
+
_iteratorError = err;
|
|
281
|
+
} finally{
|
|
282
|
+
try {
|
|
283
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
284
|
+
_iterator.return();
|
|
285
|
+
}
|
|
286
|
+
} finally{
|
|
287
|
+
if (_didIteratorError) {
|
|
288
|
+
throw _iteratorError;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return counter;
|
|
293
|
+
}
|
|
294
|
+
var handlers = this.events.get(event);
|
|
295
|
+
if (handlers === null || handlers === void 0 ? void 0 : handlers.size) {
|
|
296
|
+
return handlers.size;
|
|
297
|
+
}
|
|
298
|
+
return counter;
|
|
299
|
+
}
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
/**
|
|
303
|
+
* Deletes all existing subscriptions
|
|
304
|
+
*/ key: "clear",
|
|
305
|
+
value: function clear() {
|
|
306
|
+
this.events.clear();
|
|
307
|
+
this.tokens.clear();
|
|
308
|
+
}
|
|
309
|
+
},
|
|
310
|
+
{
|
|
311
|
+
key: "deliver",
|
|
312
|
+
value: function deliver(path, event) {
|
|
313
|
+
for(var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++){
|
|
314
|
+
args[_key - 2] = arguments[_key];
|
|
315
|
+
}
|
|
316
|
+
var handlers = this.events.get(path);
|
|
317
|
+
if (handlers && handlers.size) {
|
|
318
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
319
|
+
try {
|
|
320
|
+
for(var _iterator = handlers.values()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
321
|
+
var handler = _step.value;
|
|
322
|
+
handler.apply(void 0, [
|
|
323
|
+
event
|
|
324
|
+
].concat(_to_consumable_array(args)));
|
|
325
|
+
}
|
|
326
|
+
} catch (err) {
|
|
327
|
+
_didIteratorError = true;
|
|
328
|
+
_iteratorError = err;
|
|
329
|
+
} finally{
|
|
330
|
+
try {
|
|
331
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
332
|
+
_iterator.return();
|
|
333
|
+
}
|
|
334
|
+
} finally{
|
|
335
|
+
if (_didIteratorError) {
|
|
336
|
+
throw _iteratorError;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
]);
|
|
344
|
+
return TinyPubSub;
|
|
345
|
+
}();
|
|
346
|
+
var pubsub = new TinyPubSub();
|
|
347
|
+
// ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/pubsub/core/src/symbols.ts
|
|
348
|
+
var PubSubPluginSymbol = Symbol.for("PubSubPlugin");
|
|
349
|
+
// ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/pubsub/core/src/plugin.ts
|
|
350
|
+
var _PubSubPlugin = /*#__PURE__*/ function() {
|
|
351
|
+
function _PubSubPlugin(config) {
|
|
352
|
+
_class_call_check(this, _PubSubPlugin);
|
|
353
|
+
this.name = "pub-sub";
|
|
354
|
+
this.symbol = _PubSubPlugin.Symbol;
|
|
355
|
+
var _config_expressionName;
|
|
356
|
+
this.expressionName = (_config_expressionName = config === null || config === void 0 ? void 0 : config.expressionName) !== null && _config_expressionName !== void 0 ? _config_expressionName : "publish";
|
|
357
|
+
this.pubsub = pubsub;
|
|
358
|
+
}
|
|
359
|
+
_create_class(_PubSubPlugin, [
|
|
360
|
+
{
|
|
361
|
+
key: "apply",
|
|
362
|
+
value: function apply(player) {
|
|
363
|
+
var _this = this;
|
|
364
|
+
var existing = player.findPlugin(PubSubPluginSymbol);
|
|
365
|
+
if (existing !== void 0) {
|
|
366
|
+
this.pubsub = existing.pubsub;
|
|
367
|
+
}
|
|
368
|
+
player.hooks.expressionEvaluator.tap(this.name, function(expEvaluator) {
|
|
369
|
+
var existingExpression = expEvaluator.operators.expressions.get(_this.expressionName);
|
|
370
|
+
if (existingExpression) {
|
|
371
|
+
player.logger.warn("[PubSubPlugin] expression ".concat(_this.expressionName, " is already registered."));
|
|
372
|
+
} else {
|
|
373
|
+
var _this1 = _this;
|
|
374
|
+
expEvaluator.addExpressionFunction(_this.expressionName, function(_ctx, event) {
|
|
375
|
+
for(var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++){
|
|
376
|
+
args[_key - 2] = arguments[_key];
|
|
377
|
+
}
|
|
378
|
+
if (typeof event === "string") {
|
|
379
|
+
_this1.publish.apply(_this1, [
|
|
380
|
+
event
|
|
381
|
+
].concat(_to_consumable_array(args)));
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
});
|
|
386
|
+
player.hooks.onEnd.tap(this.name, function() {
|
|
387
|
+
_this.clear();
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
},
|
|
391
|
+
{
|
|
392
|
+
/**
|
|
393
|
+
* A way of publishing an event, notifying any listeners
|
|
394
|
+
*
|
|
395
|
+
* @param event - The name of the event to publish. Can take sub-topics like: foo.bar
|
|
396
|
+
* @param data - Any additional data to attach to the event
|
|
397
|
+
*/ key: "publish",
|
|
398
|
+
value: function publish(event) {
|
|
399
|
+
for(var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
|
|
400
|
+
args[_key - 1] = arguments[_key];
|
|
401
|
+
}
|
|
402
|
+
var _this_pubsub;
|
|
403
|
+
(_this_pubsub = this.pubsub).publish.apply(_this_pubsub, [
|
|
404
|
+
event
|
|
405
|
+
].concat(_to_consumable_array(args)));
|
|
406
|
+
}
|
|
407
|
+
},
|
|
408
|
+
{
|
|
409
|
+
/**
|
|
410
|
+
* Subscribe to an event with the given name. The handler will get called for any published event
|
|
411
|
+
*
|
|
412
|
+
* @param event - The name of the event to subscribe to
|
|
413
|
+
* @param handler - A function to be called when the event is triggered
|
|
414
|
+
* @returns A token to be used to unsubscribe from the event
|
|
415
|
+
*/ key: "subscribe",
|
|
416
|
+
value: function subscribe(event, handler) {
|
|
417
|
+
return this.pubsub.subscribe(event, handler);
|
|
418
|
+
}
|
|
419
|
+
},
|
|
420
|
+
{
|
|
421
|
+
/**
|
|
422
|
+
* Remove any subscriptions using the given token
|
|
423
|
+
*
|
|
424
|
+
* @param token - A token from a `subscribe` call
|
|
425
|
+
*/ key: "unsubscribe",
|
|
426
|
+
value: function unsubscribe(token) {
|
|
427
|
+
this.pubsub.unsubscribe(token);
|
|
428
|
+
}
|
|
429
|
+
},
|
|
430
|
+
{
|
|
431
|
+
/**
|
|
432
|
+
* Remove all subscriptions
|
|
433
|
+
*/ key: "clear",
|
|
434
|
+
value: function clear() {
|
|
435
|
+
this.pubsub.clear();
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
]);
|
|
439
|
+
return _PubSubPlugin;
|
|
440
|
+
}();
|
|
441
|
+
_PubSubPlugin.Symbol = PubSubPluginSymbol;
|
|
442
|
+
var PubSubPlugin = _PubSubPlugin;
|
|
443
|
+
// ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/pubsub/core/src/handler.ts
|
|
444
|
+
var PubSubHandlerPlugin = /*#__PURE__*/ function() {
|
|
445
|
+
function PubSubHandlerPlugin(subscriptions) {
|
|
446
|
+
_class_call_check(this, PubSubHandlerPlugin);
|
|
447
|
+
this.name = "pubsub-handler";
|
|
448
|
+
this.subscriptions = subscriptions;
|
|
449
|
+
}
|
|
450
|
+
_create_class(PubSubHandlerPlugin, [
|
|
451
|
+
{
|
|
452
|
+
key: "apply",
|
|
453
|
+
value: function apply(player) {
|
|
454
|
+
var _this = this;
|
|
455
|
+
var pubsub2 = getPubSubPlugin(player);
|
|
456
|
+
player.hooks.onStart.tap(this.name, function() {
|
|
457
|
+
_this.subscriptions.forEach(function(handler, key) {
|
|
458
|
+
pubsub2.subscribe(key, function(_) {
|
|
459
|
+
for(var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
|
|
460
|
+
args[_key - 1] = arguments[_key];
|
|
461
|
+
}
|
|
462
|
+
var state = player.getState();
|
|
463
|
+
if (state.status === "in-progress") {
|
|
464
|
+
return handler.apply(void 0, [
|
|
465
|
+
state
|
|
466
|
+
].concat(_to_consumable_array(args)));
|
|
467
|
+
}
|
|
468
|
+
player.logger.info("[PubSubHandlerPlugin] subscriber for ".concat(key, " was called when player was not in-progress"));
|
|
469
|
+
});
|
|
470
|
+
});
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
]);
|
|
475
|
+
return PubSubHandlerPlugin;
|
|
476
|
+
}();
|
|
477
|
+
return __toCommonJS(src_exports);
|
|
478
|
+
}();
|
|
479
|
+
//# sourceMappingURL=index.global.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/pubsub/core/src/index.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/pubsub/core/src/pubsub.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/pubsub/core/src/symbols.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/pubsub/core/src/plugin.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/pubsub/core/src/utils.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/pubsub/core/src/handler.ts"],"names":["handlers","pubsub"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACeA,WAAS,WAAW,OAAe;AACjC,WAAO,MAAM,MAAM,GAAG,EAAE,OAAiB,CAAC,MAAM,MAAM,UAAU;AAC9D,UAAI,UAAU,GAAG;AACf,e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AAAA;AAAA;AAAA;AAAA,IAKA,QAAQ;AACN,WAAK,OAAO,MAAM;AAAA,IACpB;AAAA,EACF;AArFE,EAHW,cAGJ,SAAS;AAHX,MAAM,eAAN;;;AChBA,WAAS,gBAAgB,QAAgB;AAC9C,UAAM,WAAW,OAAO,WAAyB,kBAAkB;AACnE,UAAM,SAAS,YAAY,IAAI,aAAa;AAE5C,QAAI,CAAC,UAAU;AACb,aAAO,eAAe,MAAM;AAAA,IAC9B;AAEA,WAAO;AAAA,EACT;;;ACHO,MAAM,sBAAN,MAAkD;AAAA,IAIvD,YAAY,eAAgC;AAH5C,kBAAO;AAIL,WAAK,gBAAgB;AAAA,IACvB;AAAA,IAEA,MAAM,QAAgB;AACpB,YAAMC,UAAS,gBAAgB,MAAM;AAErC,aAAO,MAAM,QAAQ,IAAI,KAAK,MAAM,MAAM;AACxC,aAAK,cAAc,QAAQ,CAAC,SAAS,QAAQ;AAC3C,UAAAA,QAAO,UAAU,KAAK,CAAC,MAAM,SAAS;AACpC,kBAAM,QAAQ,OAAO,SAAS;AAE9B,gBAAI,MAAM,WAAW,eAAe;AAClC,qBAAO,QAAQ,OAAO,GAAG,IAAI;AAAA,YAC/B;AAEA,mBAAO,OAAO;AAAA,cACZ,wCAAwC,GAAG;AAAA,YAC7C;AAAA,UACF,CAAC;AAAA,QACH,CAAC;AAAA,MACH,CAAC;AAAA,IACH;AAAA,EACF","sourcesContent":["export * from \"./plugin\";\nexport * from \"./symbols\";\nexport * from \"./handler\";\n","/**\n * Based off the pubsub-js library and rewritten to match the same used APIs but modified so that\n * multiple arguments could be passed into the publish and subscription handlers.\n */\n\nexport type SubscribeHandler<T extends string, A extends unknown[]> = (\n type: T,\n ...args: A\n) => void;\n\nexport type PubSubUUID = `uuid_${number}`;\n\n/**\n * Split a string into an array of event layers\n */\nfunction splitEvent(event: string) {\n return event.split(\".\").reduce<string[]>((prev, curr, index) => {\n if (index === 0) {\n return [curr];\n }\n\n return [...prev, `${prev[index - 1]}.${curr}`];\n }, []);\n}\n\nlet count = 1;\n\n/**\n * Tiny pubsub maker\n */\nexport class TinyPubSub {\n private events: Map<string, Map<PubSubUUID, SubscribeHandler<any, any>>>;\n private tokens: Map<PubSubUUID, string>;\n\n constructor() {\n this.events = new Map();\n this.tokens = new Map();\n }\n\n /**\n * Publish an event with any number of additional arguments\n */\n publish(event: string, ...args: unknown[]) {\n if (typeof event !== \"string\") {\n return;\n }\n\n if (event.includes(\".\")) {\n const eventKeys = splitEvent(event);\n\n eventKeys.forEach((key) => {\n this.deliver(key, event, ...args);\n });\n } else {\n this.deliver(event, event, ...args);\n }\n\n this.deliver(\"*\", event, ...args);\n }\n\n /**\n * Subscribe to an event\n *\n * Events are also heirarchical when separated by a period. Given the following:\n *\n * publish('a.b.c', 'one', 'two', 'three)\n *\n * The subscribe event will be called when the event is passed as 'a', 'a.b', or 'a.b.c'.\n *\n * @example\n * // subscribes to the top level 'a' publish\n * subscribe('a', (event, ...args) => console.log(event, ...args))\n */\n subscribe(event: string, handler: SubscribeHandler<any, any>) {\n const uuid = `uuid_${++count}`;\n\n if (typeof event === \"string\") {\n if (!this.events.has(event)) {\n this.events.set(event, new Map());\n }\n\n const handlers = this.events.get(event);\n handlers!.set(uuid as PubSubUUID, handler);\n this.tokens.set(uuid as PubSubUUID, event);\n }\n\n return uuid;\n }\n\n /**\n * Unsubscribes to a specific subscription given it's symbol or an entire\n * event when passed as a string.\n *\n * When existing subscriptions exist for heirarchical events such as 'a.b.c',\n * when passing an event 'a' to unsubscribe, all subscriptions for 'a', 'a.b',\n * & 'a.b.c' will be unsubscribed as well.\n */\n unsubscribe(value: string | symbol) {\n if (typeof value === \"string\" && value.startsWith(\"uuid\")) {\n const path = this.tokens.get(value as PubSubUUID);\n\n if (typeof path === \"undefined\") {\n return;\n }\n\n const innerPath = this.events.get(path);\n innerPath?.delete(value as PubSubUUID);\n this.tokens.delete(value as PubSubUUID);\n return;\n }\n\n if (typeof value === \"string\") {\n for (const key of this.events.keys()) {\n if (key.indexOf(value) === 0) {\n const tokens = this.events.get(key);\n\n if (tokens && tokens.size) {\n // eslint-disable-next-line max-depth\n for (const token of tokens.keys()) {\n this.tokens.delete(token);\n }\n }\n\n this.events.delete(key);\n }\n }\n }\n }\n\n /**\n * Get the number of subscriptions for a specific event, or when left blank\n * will return the overall number of subscriptions for the entire pubsub.\n */\n count(event?: string) {\n let counter = 0;\n\n if (typeof event === \"undefined\") {\n for (const handlers of this.events.values()) {\n counter += handlers.size;\n }\n\n return counter;\n }\n\n const handlers = this.events.get(event);\n\n if (handlers?.size) {\n return handlers.size;\n }\n\n return counter;\n }\n\n /**\n * Deletes all existing subscriptions\n */\n clear() {\n this.events.clear();\n this.tokens.clear();\n }\n\n private deliver(path: string, event: string, ...args: unknown[]) {\n const handlers = this.events.get(path);\n\n if (handlers && handlers.size) {\n for (const handler of handlers.values()) {\n handler(event, ...args);\n }\n }\n }\n}\n\nexport const pubsub = new TinyPubSub();\n","export const PubSubPluginSymbol = Symbol.for(\"PubSubPlugin\");\n","import type {\n Player,\n PlayerPlugin,\n ExpressionContext,\n} from \"@player-ui/player\";\nimport type { SubscribeHandler, TinyPubSub } from \"./pubsub\";\nimport { pubsub } from \"./pubsub\";\nimport { PubSubPluginSymbol } from \"./symbols\";\n\nexport interface PubSubConfig {\n /** A custom expression name to register */\n expressionName: string;\n}\n\n/**\n * The PubSubPlugin is a great way to enable your FRF content to publish events back to your app\n * It injects a publish() function into the expression language, and will forward all events back to any subscribers.\n *\n * Published/Subscribed events support a hierarchy:\n * - publish('foo', 'data') -- will trigger any listeners for 'foo'\n * - publish('foo.bar', 'data') -- will trigger any listeners for 'foo' or 'foo.bar'\n *\n */\nexport class PubSubPlugin implements PlayerPlugin {\n name = \"pub-sub\";\n\n static Symbol = PubSubPluginSymbol;\n public readonly symbol = PubSubPlugin.Symbol;\n\n protected pubsub: TinyPubSub;\n\n private expressionName: string;\n\n constructor(config?: PubSubConfig) {\n this.expressionName = config?.expressionName ?? \"publish\";\n this.pubsub = pubsub;\n }\n\n apply(player: Player) {\n // if there is already a pubsub plugin, reuse its pubsub instance\n // to maintain the singleton across bundles for iOS/Android\n const existing = player.findPlugin<PubSubPlugin>(PubSubPluginSymbol);\n if (existing !== undefined) {\n this.pubsub = existing.pubsub;\n }\n\n player.hooks.expressionEvaluator.tap(this.name, (expEvaluator) => {\n const existingExpression = expEvaluator.operators.expressions.get(\n this.expressionName,\n );\n\n if (existingExpression) {\n player.logger.warn(\n `[PubSubPlugin] expression ${this.expressionName} is already registered.`,\n );\n } else {\n expEvaluator.addExpressionFunction(\n this.expressionName,\n (_ctx: ExpressionContext, event: unknown, ...args: unknown[]) => {\n if (typeof event === \"string\") {\n this.publish(event, ...args);\n }\n },\n );\n }\n });\n\n player.hooks.onEnd.tap(this.name, () => {\n this.clear();\n });\n }\n\n /**\n * A way of publishing an event, notifying any listeners\n *\n * @param event - The name of the event to publish. Can take sub-topics like: foo.bar\n * @param data - Any additional data to attach to the event\n */\n publish(event: string, ...args: unknown[]) {\n this.pubsub.publish(event, ...args);\n }\n\n /**\n * Subscribe to an event with the given name. The handler will get called for any published event\n *\n * @param event - The name of the event to subscribe to\n * @param handler - A function to be called when the event is triggered\n * @returns A token to be used to unsubscribe from the event\n */\n subscribe<T extends string, A extends unknown[]>(\n event: T,\n handler: SubscribeHandler<T, A>,\n ) {\n return this.pubsub.subscribe(event, handler);\n }\n\n /**\n * Remove any subscriptions using the given token\n *\n * @param token - A token from a `subscribe` call\n */\n unsubscribe(token: string) {\n this.pubsub.unsubscribe(token);\n }\n\n /**\n * Remove all subscriptions\n */\n clear() {\n this.pubsub.clear();\n }\n}\n","import type { Player } from \"@player-ui/player\";\nimport { PubSubPlugin } from \"./plugin\";\nimport { PubSubPluginSymbol } from \"./symbols\";\n\n/**\n * Returns the existing PubSubPlugin or creates and registers a new plugin\n */\nexport function getPubSubPlugin(player: Player) {\n const existing = player.findPlugin<PubSubPlugin>(PubSubPluginSymbol);\n const plugin = existing || new PubSubPlugin();\n\n if (!existing) {\n player.registerPlugin(plugin);\n }\n\n return plugin;\n}\n","import type { Player, PlayerPlugin, InProgressState } from \"@player-ui/player\";\nimport { getPubSubPlugin } from \"./utils\";\n\nexport type PubSubHandler<T extends unknown[]> = (\n context: InProgressState,\n ...args: T\n) => void;\n\nexport type SubscriptionMap = Map<string, PubSubHandler<any>>;\n\n/**\n * Plugin to easily add subscribers to the PubSubPlugin\n */\nexport class PubSubHandlerPlugin implements PlayerPlugin {\n name = \"pubsub-handler\";\n private subscriptions: SubscriptionMap;\n\n constructor(subscriptions: SubscriptionMap) {\n this.subscriptions = subscriptions;\n }\n\n apply(player: Player) {\n const pubsub = getPubSubPlugin(player);\n\n player.hooks.onStart.tap(this.name, () => {\n this.subscriptions.forEach((handler, key) => {\n pubsub.subscribe(key, (_, ...args) => {\n const state = player.getState();\n\n if (state.status === \"in-progress\") {\n return handler(state, ...args);\n }\n\n player.logger.info(\n `[PubSubHandlerPlugin] subscriber for ${key} was called when player was not in-progress`,\n );\n });\n });\n });\n }\n}\n"]}
|