@player-ui/pubsub-plugin 0.4.0-next.3 → 0.4.0
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/pubsub-plugin.dev.js +553 -0
- package/dist/pubsub-plugin.prod.js +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,553 @@
|
|
|
1
|
+
(function webpackUniversalModuleDefinition(root, factory) {
|
|
2
|
+
if(typeof exports === 'object' && typeof module === 'object')
|
|
3
|
+
module.exports = factory();
|
|
4
|
+
else if(typeof define === 'function' && define.amd)
|
|
5
|
+
define([], factory);
|
|
6
|
+
else if(typeof exports === 'object')
|
|
7
|
+
exports["PubSubPlugin"] = factory();
|
|
8
|
+
else
|
|
9
|
+
root["PubSubPlugin"] = factory();
|
|
10
|
+
})(this, function() {
|
|
11
|
+
return /******/ (function(modules) { // webpackBootstrap
|
|
12
|
+
/******/ // The module cache
|
|
13
|
+
/******/ var installedModules = {};
|
|
14
|
+
/******/
|
|
15
|
+
/******/ // The require function
|
|
16
|
+
/******/ function __webpack_require__(moduleId) {
|
|
17
|
+
/******/
|
|
18
|
+
/******/ // Check if module is in cache
|
|
19
|
+
/******/ if(installedModules[moduleId]) {
|
|
20
|
+
/******/ return installedModules[moduleId].exports;
|
|
21
|
+
/******/ }
|
|
22
|
+
/******/ // Create a new module (and put it into the cache)
|
|
23
|
+
/******/ var module = installedModules[moduleId] = {
|
|
24
|
+
/******/ i: moduleId,
|
|
25
|
+
/******/ l: false,
|
|
26
|
+
/******/ exports: {}
|
|
27
|
+
/******/ };
|
|
28
|
+
/******/
|
|
29
|
+
/******/ // Execute the module function
|
|
30
|
+
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
|
31
|
+
/******/
|
|
32
|
+
/******/ // Flag the module as loaded
|
|
33
|
+
/******/ module.l = true;
|
|
34
|
+
/******/
|
|
35
|
+
/******/ // Return the exports of the module
|
|
36
|
+
/******/ return module.exports;
|
|
37
|
+
/******/ }
|
|
38
|
+
/******/
|
|
39
|
+
/******/
|
|
40
|
+
/******/ // expose the modules object (__webpack_modules__)
|
|
41
|
+
/******/ __webpack_require__.m = modules;
|
|
42
|
+
/******/
|
|
43
|
+
/******/ // expose the module cache
|
|
44
|
+
/******/ __webpack_require__.c = installedModules;
|
|
45
|
+
/******/
|
|
46
|
+
/******/ // define getter function for harmony exports
|
|
47
|
+
/******/ __webpack_require__.d = function(exports, name, getter) {
|
|
48
|
+
/******/ if(!__webpack_require__.o(exports, name)) {
|
|
49
|
+
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
|
|
50
|
+
/******/ }
|
|
51
|
+
/******/ };
|
|
52
|
+
/******/
|
|
53
|
+
/******/ // define __esModule on exports
|
|
54
|
+
/******/ __webpack_require__.r = function(exports) {
|
|
55
|
+
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
56
|
+
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
57
|
+
/******/ }
|
|
58
|
+
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
59
|
+
/******/ };
|
|
60
|
+
/******/
|
|
61
|
+
/******/ // create a fake namespace object
|
|
62
|
+
/******/ // mode & 1: value is a module id, require it
|
|
63
|
+
/******/ // mode & 2: merge all properties of value into the ns
|
|
64
|
+
/******/ // mode & 4: return value when already ns object
|
|
65
|
+
/******/ // mode & 8|1: behave like require
|
|
66
|
+
/******/ __webpack_require__.t = function(value, mode) {
|
|
67
|
+
/******/ if(mode & 1) value = __webpack_require__(value);
|
|
68
|
+
/******/ if(mode & 8) return value;
|
|
69
|
+
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
|
|
70
|
+
/******/ var ns = Object.create(null);
|
|
71
|
+
/******/ __webpack_require__.r(ns);
|
|
72
|
+
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
|
|
73
|
+
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
|
|
74
|
+
/******/ return ns;
|
|
75
|
+
/******/ };
|
|
76
|
+
/******/
|
|
77
|
+
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
|
78
|
+
/******/ __webpack_require__.n = function(module) {
|
|
79
|
+
/******/ var getter = module && module.__esModule ?
|
|
80
|
+
/******/ function getDefault() { return module['default']; } :
|
|
81
|
+
/******/ function getModuleExports() { return module; };
|
|
82
|
+
/******/ __webpack_require__.d(getter, 'a', getter);
|
|
83
|
+
/******/ return getter;
|
|
84
|
+
/******/ };
|
|
85
|
+
/******/
|
|
86
|
+
/******/ // Object.prototype.hasOwnProperty.call
|
|
87
|
+
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
|
88
|
+
/******/
|
|
89
|
+
/******/ // __webpack_public_path__
|
|
90
|
+
/******/ __webpack_require__.p = "";
|
|
91
|
+
/******/
|
|
92
|
+
/******/
|
|
93
|
+
/******/ // Load entry module and return exports
|
|
94
|
+
/******/ return __webpack_require__(__webpack_require__.s = "./bazel-out/k8-fastbuild/bin/plugins/pubsub/core/dist/index.esm.js");
|
|
95
|
+
/******/ })
|
|
96
|
+
/************************************************************************/
|
|
97
|
+
/******/ ({
|
|
98
|
+
|
|
99
|
+
/***/ "./bazel-out/k8-fastbuild/bin/plugins/pubsub/core/dist/index.esm.js":
|
|
100
|
+
/*!**************************************************************************!*\
|
|
101
|
+
!*** ./bazel-out/k8-fastbuild/bin/plugins/pubsub/core/dist/index.esm.js ***!
|
|
102
|
+
\**************************************************************************/
|
|
103
|
+
/*! exports provided: PubSubPlugin, PubSubPluginSymbol */
|
|
104
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
105
|
+
|
|
106
|
+
"use strict";
|
|
107
|
+
__webpack_require__.r(__webpack_exports__);
|
|
108
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "PubSubPlugin", function() { return PubSubPlugin; });
|
|
109
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "PubSubPluginSymbol", function() { return PubSubPluginSymbol; });
|
|
110
|
+
/* harmony import */ var pubsub_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! pubsub-js */ "./node_modules/pubsub-js/src/pubsub.js");
|
|
111
|
+
/* harmony import */ var pubsub_js__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(pubsub_js__WEBPACK_IMPORTED_MODULE_0__);
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
const PubSubPluginSymbol = Symbol.for("PubSubPlugin");
|
|
115
|
+
|
|
116
|
+
const _PubSubPlugin = class {
|
|
117
|
+
constructor(config) {
|
|
118
|
+
this.name = "pub-sub";
|
|
119
|
+
this.symbol = _PubSubPlugin.Symbol;
|
|
120
|
+
var _a;
|
|
121
|
+
this.expressionName = (_a = config == null ? void 0 : config.expressionName) != null ? _a : "publish";
|
|
122
|
+
}
|
|
123
|
+
apply(player) {
|
|
124
|
+
player.hooks.expressionEvaluator.tap(this.name, (expEvaluator) => {
|
|
125
|
+
expEvaluator.addExpressionFunction(this.expressionName, (_ctx, event, data) => {
|
|
126
|
+
if (typeof event === "string") {
|
|
127
|
+
this.publish(event, data);
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
publish(event, data) {
|
|
133
|
+
pubsub_js__WEBPACK_IMPORTED_MODULE_0___default.a.publishSync(event, data);
|
|
134
|
+
}
|
|
135
|
+
subscribe(event, handler) {
|
|
136
|
+
return pubsub_js__WEBPACK_IMPORTED_MODULE_0___default.a.subscribe(event, handler);
|
|
137
|
+
}
|
|
138
|
+
unsubscribe(token) {
|
|
139
|
+
pubsub_js__WEBPACK_IMPORTED_MODULE_0___default.a.unsubscribe(token);
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
let PubSubPlugin = _PubSubPlugin;
|
|
143
|
+
PubSubPlugin.Symbol = PubSubPluginSymbol;
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
//# sourceMappingURL=index.esm.js.map
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
/***/ }),
|
|
150
|
+
|
|
151
|
+
/***/ "./node_modules/pubsub-js/src/pubsub.js":
|
|
152
|
+
/*!**********************************************!*\
|
|
153
|
+
!*** ./node_modules/pubsub-js/src/pubsub.js ***!
|
|
154
|
+
\**********************************************/
|
|
155
|
+
/*! no static exports found */
|
|
156
|
+
/***/ (function(module, exports, __webpack_require__) {
|
|
157
|
+
|
|
158
|
+
/* WEBPACK VAR INJECTION */(function(module) {/**
|
|
159
|
+
* Copyright (c) 2010,2011,2012,2013,2014 Morgan Roderick http://roderick.dk
|
|
160
|
+
* License: MIT - http://mrgnrdrck.mit-license.org
|
|
161
|
+
*
|
|
162
|
+
* https://github.com/mroderick/PubSubJS
|
|
163
|
+
*/
|
|
164
|
+
|
|
165
|
+
(function (root, factory){
|
|
166
|
+
'use strict';
|
|
167
|
+
|
|
168
|
+
var PubSub = {};
|
|
169
|
+
|
|
170
|
+
if (root.PubSub) {
|
|
171
|
+
PubSub = root.PubSub;
|
|
172
|
+
console.warn("PubSub already loaded, using existing version");
|
|
173
|
+
} else {
|
|
174
|
+
root.PubSub = PubSub;
|
|
175
|
+
factory(PubSub);
|
|
176
|
+
}
|
|
177
|
+
// CommonJS and Node.js module support
|
|
178
|
+
if (true){
|
|
179
|
+
if (module !== undefined && module.exports) {
|
|
180
|
+
exports = module.exports = PubSub; // Node.js specific `module.exports`
|
|
181
|
+
}
|
|
182
|
+
exports.PubSub = PubSub; // CommonJS module 1.1.1 spec
|
|
183
|
+
module.exports = exports = PubSub; // CommonJS
|
|
184
|
+
}
|
|
185
|
+
// AMD support
|
|
186
|
+
/* eslint-disable no-undef */
|
|
187
|
+
else {}
|
|
188
|
+
|
|
189
|
+
}(( typeof window === 'object' && window ) || this, function (PubSub){
|
|
190
|
+
'use strict';
|
|
191
|
+
|
|
192
|
+
var messages = {},
|
|
193
|
+
lastUid = -1,
|
|
194
|
+
ALL_SUBSCRIBING_MSG = '*';
|
|
195
|
+
|
|
196
|
+
function hasKeys(obj){
|
|
197
|
+
var key;
|
|
198
|
+
|
|
199
|
+
for (key in obj){
|
|
200
|
+
if ( Object.prototype.hasOwnProperty.call(obj, key) ){
|
|
201
|
+
return true;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Returns a function that throws the passed exception, for use as argument for setTimeout
|
|
209
|
+
* @alias throwException
|
|
210
|
+
* @function
|
|
211
|
+
* @param { Object } ex An Error object
|
|
212
|
+
*/
|
|
213
|
+
function throwException( ex ){
|
|
214
|
+
return function reThrowException(){
|
|
215
|
+
throw ex;
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function callSubscriberWithDelayedExceptions( subscriber, message, data ){
|
|
220
|
+
try {
|
|
221
|
+
subscriber( message, data );
|
|
222
|
+
} catch( ex ){
|
|
223
|
+
setTimeout( throwException( ex ), 0);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function callSubscriberWithImmediateExceptions( subscriber, message, data ){
|
|
228
|
+
subscriber( message, data );
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function deliverMessage( originalMessage, matchedMessage, data, immediateExceptions ){
|
|
232
|
+
var subscribers = messages[matchedMessage],
|
|
233
|
+
callSubscriber = immediateExceptions ? callSubscriberWithImmediateExceptions : callSubscriberWithDelayedExceptions,
|
|
234
|
+
s;
|
|
235
|
+
|
|
236
|
+
if ( !Object.prototype.hasOwnProperty.call( messages, matchedMessage ) ) {
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
for (s in subscribers){
|
|
241
|
+
if ( Object.prototype.hasOwnProperty.call(subscribers, s)){
|
|
242
|
+
callSubscriber( subscribers[s], originalMessage, data );
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function createDeliveryFunction( message, data, immediateExceptions ){
|
|
248
|
+
return function deliverNamespaced(){
|
|
249
|
+
var topic = String( message ),
|
|
250
|
+
position = topic.lastIndexOf( '.' );
|
|
251
|
+
|
|
252
|
+
// deliver the message as it is now
|
|
253
|
+
deliverMessage(message, message, data, immediateExceptions);
|
|
254
|
+
|
|
255
|
+
// trim the hierarchy and deliver message to each level
|
|
256
|
+
while( position !== -1 ){
|
|
257
|
+
topic = topic.substr( 0, position );
|
|
258
|
+
position = topic.lastIndexOf('.');
|
|
259
|
+
deliverMessage( message, topic, data, immediateExceptions );
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
deliverMessage(message, ALL_SUBSCRIBING_MSG, data, immediateExceptions);
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function hasDirectSubscribersFor( message ) {
|
|
267
|
+
var topic = String( message ),
|
|
268
|
+
found = Boolean(Object.prototype.hasOwnProperty.call( messages, topic ) && hasKeys(messages[topic]));
|
|
269
|
+
|
|
270
|
+
return found;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function messageHasSubscribers( message ){
|
|
274
|
+
var topic = String( message ),
|
|
275
|
+
found = hasDirectSubscribersFor(topic) || hasDirectSubscribersFor(ALL_SUBSCRIBING_MSG),
|
|
276
|
+
position = topic.lastIndexOf( '.' );
|
|
277
|
+
|
|
278
|
+
while ( !found && position !== -1 ){
|
|
279
|
+
topic = topic.substr( 0, position );
|
|
280
|
+
position = topic.lastIndexOf( '.' );
|
|
281
|
+
found = hasDirectSubscribersFor(topic);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
return found;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function publish( message, data, sync, immediateExceptions ){
|
|
288
|
+
message = (typeof message === 'symbol') ? message.toString() : message;
|
|
289
|
+
|
|
290
|
+
var deliver = createDeliveryFunction( message, data, immediateExceptions ),
|
|
291
|
+
hasSubscribers = messageHasSubscribers( message );
|
|
292
|
+
|
|
293
|
+
if ( !hasSubscribers ){
|
|
294
|
+
return false;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
if ( sync === true ){
|
|
298
|
+
deliver();
|
|
299
|
+
} else {
|
|
300
|
+
setTimeout( deliver, 0 );
|
|
301
|
+
}
|
|
302
|
+
return true;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Publishes the message, passing the data to it's subscribers
|
|
307
|
+
* @function
|
|
308
|
+
* @alias publish
|
|
309
|
+
* @param { String } message The message to publish
|
|
310
|
+
* @param {} data The data to pass to subscribers
|
|
311
|
+
* @return { Boolean }
|
|
312
|
+
*/
|
|
313
|
+
PubSub.publish = function( message, data ){
|
|
314
|
+
return publish( message, data, false, PubSub.immediateExceptions );
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Publishes the message synchronously, passing the data to it's subscribers
|
|
319
|
+
* @function
|
|
320
|
+
* @alias publishSync
|
|
321
|
+
* @param { String } message The message to publish
|
|
322
|
+
* @param {} data The data to pass to subscribers
|
|
323
|
+
* @return { Boolean }
|
|
324
|
+
*/
|
|
325
|
+
PubSub.publishSync = function( message, data ){
|
|
326
|
+
return publish( message, data, true, PubSub.immediateExceptions );
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Subscribes the passed function to the passed message. Every returned token is unique and should be stored if you need to unsubscribe
|
|
331
|
+
* @function
|
|
332
|
+
* @alias subscribe
|
|
333
|
+
* @param { String } message The message to subscribe to
|
|
334
|
+
* @param { Function } func The function to call when a new message is published
|
|
335
|
+
* @return { String }
|
|
336
|
+
*/
|
|
337
|
+
PubSub.subscribe = function( message, func ){
|
|
338
|
+
if ( typeof func !== 'function'){
|
|
339
|
+
return false;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
message = (typeof message === 'symbol') ? message.toString() : message;
|
|
343
|
+
|
|
344
|
+
// message is not registered yet
|
|
345
|
+
if ( !Object.prototype.hasOwnProperty.call( messages, message ) ){
|
|
346
|
+
messages[message] = {};
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
// forcing token as String, to allow for future expansions without breaking usage
|
|
350
|
+
// and allow for easy use as key names for the 'messages' object
|
|
351
|
+
var token = 'uid_' + String(++lastUid);
|
|
352
|
+
messages[message][token] = func;
|
|
353
|
+
|
|
354
|
+
// return token for unsubscribing
|
|
355
|
+
return token;
|
|
356
|
+
};
|
|
357
|
+
|
|
358
|
+
PubSub.subscribeAll = function( func ){
|
|
359
|
+
return PubSub.subscribe(ALL_SUBSCRIBING_MSG, func);
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* Subscribes the passed function to the passed message once
|
|
364
|
+
* @function
|
|
365
|
+
* @alias subscribeOnce
|
|
366
|
+
* @param { String } message The message to subscribe to
|
|
367
|
+
* @param { Function } func The function to call when a new message is published
|
|
368
|
+
* @return { PubSub }
|
|
369
|
+
*/
|
|
370
|
+
PubSub.subscribeOnce = function( message, func ){
|
|
371
|
+
var token = PubSub.subscribe( message, function(){
|
|
372
|
+
// before func apply, unsubscribe message
|
|
373
|
+
PubSub.unsubscribe( token );
|
|
374
|
+
func.apply( this, arguments );
|
|
375
|
+
});
|
|
376
|
+
return PubSub;
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* Clears all subscriptions
|
|
381
|
+
* @function
|
|
382
|
+
* @public
|
|
383
|
+
* @alias clearAllSubscriptions
|
|
384
|
+
*/
|
|
385
|
+
PubSub.clearAllSubscriptions = function clearAllSubscriptions(){
|
|
386
|
+
messages = {};
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Clear subscriptions by the topic
|
|
391
|
+
* @function
|
|
392
|
+
* @public
|
|
393
|
+
* @alias clearAllSubscriptions
|
|
394
|
+
* @return { int }
|
|
395
|
+
*/
|
|
396
|
+
PubSub.clearSubscriptions = function clearSubscriptions(topic){
|
|
397
|
+
var m;
|
|
398
|
+
for (m in messages){
|
|
399
|
+
if (Object.prototype.hasOwnProperty.call(messages, m) && m.indexOf(topic) === 0){
|
|
400
|
+
delete messages[m];
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
};
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
Count subscriptions by the topic
|
|
407
|
+
* @function
|
|
408
|
+
* @public
|
|
409
|
+
* @alias countSubscriptions
|
|
410
|
+
* @return { Array }
|
|
411
|
+
*/
|
|
412
|
+
PubSub.countSubscriptions = function countSubscriptions(topic){
|
|
413
|
+
var m;
|
|
414
|
+
// eslint-disable-next-line no-unused-vars
|
|
415
|
+
var token;
|
|
416
|
+
var count = 0;
|
|
417
|
+
for (m in messages) {
|
|
418
|
+
if (Object.prototype.hasOwnProperty.call(messages, m) && m.indexOf(topic) === 0) {
|
|
419
|
+
for (token in messages[m]) {
|
|
420
|
+
count++;
|
|
421
|
+
}
|
|
422
|
+
break;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
return count;
|
|
426
|
+
};
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
Gets subscriptions by the topic
|
|
431
|
+
* @function
|
|
432
|
+
* @public
|
|
433
|
+
* @alias getSubscriptions
|
|
434
|
+
*/
|
|
435
|
+
PubSub.getSubscriptions = function getSubscriptions(topic){
|
|
436
|
+
var m;
|
|
437
|
+
var list = [];
|
|
438
|
+
for (m in messages){
|
|
439
|
+
if (Object.prototype.hasOwnProperty.call(messages, m) && m.indexOf(topic) === 0){
|
|
440
|
+
list.push(m);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
return list;
|
|
444
|
+
};
|
|
445
|
+
|
|
446
|
+
/**
|
|
447
|
+
* Removes subscriptions
|
|
448
|
+
*
|
|
449
|
+
* - When passed a token, removes a specific subscription.
|
|
450
|
+
*
|
|
451
|
+
* - When passed a function, removes all subscriptions for that function
|
|
452
|
+
*
|
|
453
|
+
* - When passed a topic, removes all subscriptions for that topic (hierarchy)
|
|
454
|
+
* @function
|
|
455
|
+
* @public
|
|
456
|
+
* @alias subscribeOnce
|
|
457
|
+
* @param { String | Function } value A token, function or topic to unsubscribe from
|
|
458
|
+
* @example // Unsubscribing with a token
|
|
459
|
+
* var token = PubSub.subscribe('mytopic', myFunc);
|
|
460
|
+
* PubSub.unsubscribe(token);
|
|
461
|
+
* @example // Unsubscribing with a function
|
|
462
|
+
* PubSub.unsubscribe(myFunc);
|
|
463
|
+
* @example // Unsubscribing from a topic
|
|
464
|
+
* PubSub.unsubscribe('mytopic');
|
|
465
|
+
*/
|
|
466
|
+
PubSub.unsubscribe = function(value){
|
|
467
|
+
var descendantTopicExists = function(topic) {
|
|
468
|
+
var m;
|
|
469
|
+
for ( m in messages ){
|
|
470
|
+
if ( Object.prototype.hasOwnProperty.call(messages, m) && m.indexOf(topic) === 0 ){
|
|
471
|
+
// a descendant of the topic exists:
|
|
472
|
+
return true;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
return false;
|
|
477
|
+
},
|
|
478
|
+
isTopic = typeof value === 'string' && ( Object.prototype.hasOwnProperty.call(messages, value) || descendantTopicExists(value) ),
|
|
479
|
+
isToken = !isTopic && typeof value === 'string',
|
|
480
|
+
isFunction = typeof value === 'function',
|
|
481
|
+
result = false,
|
|
482
|
+
m, message, t;
|
|
483
|
+
|
|
484
|
+
if (isTopic){
|
|
485
|
+
PubSub.clearSubscriptions(value);
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
for ( m in messages ){
|
|
490
|
+
if ( Object.prototype.hasOwnProperty.call( messages, m ) ){
|
|
491
|
+
message = messages[m];
|
|
492
|
+
|
|
493
|
+
if ( isToken && message[value] ){
|
|
494
|
+
delete message[value];
|
|
495
|
+
result = value;
|
|
496
|
+
// tokens are unique, so we can just stop here
|
|
497
|
+
break;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
if (isFunction) {
|
|
501
|
+
for ( t in message ){
|
|
502
|
+
if (Object.prototype.hasOwnProperty.call(message, t) && message[t] === value){
|
|
503
|
+
delete message[t];
|
|
504
|
+
result = true;
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
return result;
|
|
512
|
+
};
|
|
513
|
+
}));
|
|
514
|
+
|
|
515
|
+
/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../webpack/buildin/module.js */ "./node_modules/webpack/buildin/module.js")(module)))
|
|
516
|
+
|
|
517
|
+
/***/ }),
|
|
518
|
+
|
|
519
|
+
/***/ "./node_modules/webpack/buildin/module.js":
|
|
520
|
+
/*!***********************************!*\
|
|
521
|
+
!*** (webpack)/buildin/module.js ***!
|
|
522
|
+
\***********************************/
|
|
523
|
+
/*! no static exports found */
|
|
524
|
+
/***/ (function(module, exports) {
|
|
525
|
+
|
|
526
|
+
module.exports = function(module) {
|
|
527
|
+
if (!module.webpackPolyfill) {
|
|
528
|
+
module.deprecate = function() {};
|
|
529
|
+
module.paths = [];
|
|
530
|
+
// module.parent = undefined by default
|
|
531
|
+
if (!module.children) module.children = [];
|
|
532
|
+
Object.defineProperty(module, "loaded", {
|
|
533
|
+
enumerable: true,
|
|
534
|
+
get: function() {
|
|
535
|
+
return module.l;
|
|
536
|
+
}
|
|
537
|
+
});
|
|
538
|
+
Object.defineProperty(module, "id", {
|
|
539
|
+
enumerable: true,
|
|
540
|
+
get: function() {
|
|
541
|
+
return module.i;
|
|
542
|
+
}
|
|
543
|
+
});
|
|
544
|
+
module.webpackPolyfill = 1;
|
|
545
|
+
}
|
|
546
|
+
return module;
|
|
547
|
+
};
|
|
548
|
+
|
|
549
|
+
|
|
550
|
+
/***/ })
|
|
551
|
+
|
|
552
|
+
/******/ });
|
|
553
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(t,e){"object"===typeof exports&&"object"===typeof module?module.exports=e():"function"===typeof define&&define.amd?define([],e):"object"===typeof exports?exports.PubSubPlugin=e():t.PubSubPlugin=e()}(this,(function(){return function(t){var e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"===typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(r,o,function(e){return t[e]}.bind(null,o));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=1)}([function(t,e,n){(function(t){!function(n,r){"use strict";var o={};n.PubSub?(o=n.PubSub,console.warn("PubSub already loaded, using existing version")):(n.PubSub=o,function(t){var e={},n=-1,r="*";function o(t){var e;for(e in t)if(Object.prototype.hasOwnProperty.call(t,e))return!0;return!1}function i(t){return function(){throw t}}function u(t,e,n){try{t(e,n)}catch(r){setTimeout(i(r),0)}}function c(t,e,n){t(e,n)}function s(t,n,r,o){var i,s=e[n],f=o?c:u;if(Object.prototype.hasOwnProperty.call(e,n))for(i in s)Object.prototype.hasOwnProperty.call(s,i)&&f(s[i],t,r)}function f(t,e,n){return function(){var o=String(t),i=o.lastIndexOf(".");for(s(t,t,e,n);-1!==i;)i=(o=o.substr(0,i)).lastIndexOf("."),s(t,o,e,n);s(t,r,e,n)}}function l(t){var n=String(t);return Boolean(Object.prototype.hasOwnProperty.call(e,n)&&o(e[n]))}function p(t){for(var e=String(t),n=l(e)||l(r),o=e.lastIndexOf(".");!n&&-1!==o;)o=(e=e.substr(0,o)).lastIndexOf("."),n=l(e);return n}function a(t,e,n,r){var o=f(t="symbol"===typeof t?t.toString():t,e,r);return!!p(t)&&(!0===n?o():setTimeout(o,0),!0)}t.publish=function(e,n){return a(e,n,!1,t.immediateExceptions)},t.publishSync=function(e,n){return a(e,n,!0,t.immediateExceptions)},t.subscribe=function(t,r){if("function"!==typeof r)return!1;t="symbol"===typeof t?t.toString():t,Object.prototype.hasOwnProperty.call(e,t)||(e[t]={});var o="uid_"+String(++n);return e[t][o]=r,o},t.subscribeAll=function(e){return t.subscribe(r,e)},t.subscribeOnce=function(e,n){var r=t.subscribe(e,(function(){t.unsubscribe(r),n.apply(this,arguments)}));return t},t.clearAllSubscriptions=function(){e={}},t.clearSubscriptions=function(t){var n;for(n in e)Object.prototype.hasOwnProperty.call(e,n)&&0===n.indexOf(t)&&delete e[n]},t.countSubscriptions=function(t){var n,r,o=0;for(n in e)if(Object.prototype.hasOwnProperty.call(e,n)&&0===n.indexOf(t)){for(r in e[n])o++;break}return o},t.getSubscriptions=function(t){var n,r=[];for(n in e)Object.prototype.hasOwnProperty.call(e,n)&&0===n.indexOf(t)&&r.push(n);return r},t.unsubscribe=function(n){var r,o,i,u=function(t){var n;for(n in e)if(Object.prototype.hasOwnProperty.call(e,n)&&0===n.indexOf(t))return!0;return!1},c="string"===typeof n&&(Object.prototype.hasOwnProperty.call(e,n)||u(n)),s=!c&&"string"===typeof n,f="function"===typeof n,l=!1;if(!c){for(r in e)if(Object.prototype.hasOwnProperty.call(e,r)){if(o=e[r],s&&o[n]){delete o[n],l=n;break}if(f)for(i in o)Object.prototype.hasOwnProperty.call(o,i)&&o[i]===n&&(delete o[i],l=!0)}return l}t.clearSubscriptions(n)}}(o)),void 0!==t&&t.exports&&(e=t.exports=o),e.PubSub=o,t.exports=e=o}("object"===typeof window&&window||this)}).call(this,n(2)(t))},function(t,e,n){"use strict";n.r(e),n.d(e,"PubSubPlugin",(function(){return c})),n.d(e,"PubSubPluginSymbol",(function(){return i}));var r=n(0),o=n.n(r);const i=Symbol.for("PubSubPlugin"),u=class{constructor(t){var e;this.name="pub-sub",this.symbol=u.Symbol,this.expressionName=null!=(e=null==t?void 0:t.expressionName)?e:"publish"}apply(t){t.hooks.expressionEvaluator.tap(this.name,(t=>{t.addExpressionFunction(this.expressionName,((t,e,n)=>{"string"===typeof e&&this.publish(e,n)}))}))}publish(t,e){o.a.publishSync(t,e)}subscribe(t,e){return o.a.subscribe(t,e)}unsubscribe(t){o.a.unsubscribe(t)}};let c=u;c.Symbol=i},function(t,e){t.exports=function(t){return t.webpackPolyfill||(t.deprecate=function(){},t.paths=[],t.children||(t.children=[]),Object.defineProperty(t,"loaded",{enumerable:!0,get:function(){return t.l}}),Object.defineProperty(t,"id",{enumerable:!0,get:function(){return t.i}}),t.webpackPolyfill=1),t}}])}));
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@player-ui/pubsub-plugin",
|
|
3
|
-
"version": "0.4.0
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org"
|
|
7
7
|
},
|
|
8
8
|
"peerDependencies": {
|
|
9
|
-
"@player-ui/player": "0.4.0
|
|
9
|
+
"@player-ui/player": "0.4.0"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"tapable-ts": "^0.2.3",
|