Skip to content

Commit 7320ef9

Browse files
committed
Updated dist ...
1 parent 3cf8272 commit 7320ef9

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

dist/publisher.min.cjs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,11 @@
33
* @license MIT
44
* © 2015–present Frank Kudermann @ alphanull
55
*/
6-
!function(e,i){"object"==typeof exports&&"undefined"!=typeof module?i(exports):"function"==typeof define&&define.amd?define(["exports"],i):i((e="undefined"!=typeof globalThis?globalThis:e||self).publisher={})}(this,(function(e){"use strict";let i=-1;const n={async:!0,handleExceptions:!1,lenientUnsubscribe:!1},o=new Map,t=new Map,s=new Map;function r(e,i,s){const r=i===Boolean(i)?i:s,c=void 0===r?n.lenientUnsubscribe:r,a=e=>{const i=o.get(e);if(void 0===i){if(!0===c)return;throw new Error(`Unsubscribe failed. Did not find subscriber for token: ${e}`)}l(i.topic.split("/"),i,t),o.delete(e)};if(void 0===e){if(!0===c)return;throw new Error("Unsubscribe failed. No Arguments specified.")}if(Array.isArray(e))e.forEach((e=>a(e)));else if(!isNaN(parseFloat(e))&&isFinite(e))a(e);else{if(void 0===i){if(!0===c)return;throw new Error(`Unsubscribe failed. No handler for topic based unsubscribe specified ${e}`)}for(const[,n]of o)if(n.handler===i&&n.topic===e){l(e.split("/"),n,t),o.delete(n.token);break}}}function c(e,i,t,s={}){if(!o.has(e.token))return;e.options.invocations>0&&(e.options.invocations-=1,e.options.invocations<=0&&r(e.token));const{handler:c}=e;if(!0!==s.handleExceptions&&!0!==n.handleExceptions)return c(t,i);try{return c(t,i)}catch(e){window.console&&window.console.error&&window.console.error("Exception while executing publish handler: ",e)}}function a(e,i,o={},t,s,r=[]){const c=t.get("subscribers")||new Map,d=t.get("topics");for(const[,e]of c){const{condition:t}=e.options;(void 0===t||"[object Function]"===Object.prototype.toString.call(t)&&!0===t(i,s))&&(e.position=r.push(e),e.priority=e.options.priority||0,e.async=Boolean(o.async||e.options.async||n.async))}if(e.length&&d){const n=d.get(e[0]),t=d.get("*");void 0===t&&void 0===n||(void 0!==t&&a(e.slice(1,e.length),i,o,t,s,r),void 0!==n&&a(e.slice(1,e.length),i,o,n,s,r),e.shift())}return r}function d(e,i,n){const[o]=e;void 0===n.get("topics")&&n.set("topics",new Map);const t=n.get("topics");let s=t.get(o);void 0===s&&(s=new Map,t.set(o,s)),e.length<2?(void 0===s.get("subscribers")&&s.set("subscribers",new Map),s.get("subscribers").set(i.token,i)):(e.shift(),d(e,i,s))}function l(e,i,n){const[o]=e,t=n.get("topics"),s=t.get(o),r=s.get("subscribers");e.length<2?(r.delete(i.token),0===r.size&&s.delete("subscribers")):(e.shift(),l(e,i,s)),s.has("topics")&&0===s.get("topics").size&&s.delete("topics"),0===t.get(o).size&&t.delete(o)}e.configure=function(e){if(!e)throw new Error("Publisher configure: no options specified");void 0!==e.async&&(n.async=e.async),void 0!==e.handleExceptions&&(n.handleExceptions=e.handleExceptions),void 0!==e.lenientUnsubscribe&&(n.lenientUnsubscribe=e.lenientUnsubscribe)},e.publish=function(e,i,o={}){if(!0===o.persist&&s.set(e,{data:i,options:o}),e.indexOf("*")>-1)throw new Error("Publish topic cannot contain any wildcards.");const r=a(e.split("/"),i,o,t,e);let d;r.sort(((e,i)=>e.priority===i.priority?e.position-i.position:e.priority>i.priority?-1:1));const l=void 0===o.async?n.async:o.async;for(;d=r.shift();)if(l)setTimeout(c.bind(null,d,e,i,o),0);else if(!1===c(d,e,i,o)&&!1!==o.cancelable)return!1;return!0},e.removePersistentMessage=function(e){s.delete(e)},e.subscribe=function(e,r,a={}){const l=i+=1;if(void 0===e)throw new Error('Subscribe failed - "undefined" Topic.');if(e.includes("undefined"))throw new Error(`Subscribe for '${e}' failed - found 'undefined' in topic, this is almost always an error: ${l}`);if(void 0===r)throw new Error(`Subscribe for '${e}' failed - "undefined" Handler`);const f={token:l,topic:e,handler:r,options:a};if(o.set(l,f),d(e.split("/"),f,t),!0!==a.persist)return l;const p=new RegExp(`^${e.replace("*","(.+)")}(/.+)?$`);for(const[e,i]of s){if(e.match(p)){if(void 0===i.options.async?n.async:i.options.async)setTimeout(c.bind(null,f,e,i.data,a),0);else if(!1===c(f,e,i.data,a)&&!0===a.cancelable)break}}return l},e.unsubscribe=r}));
6+
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).publisher={})}(this,(function(e){"use strict";
7+
/**
8+
* The publisher module. Provides pub/sub functionality with extensive wildcard support, async/sync publishing, priority and invocation options, content based filtering & more.
9+
* @module publisher
10+
* @author Frank Kudermann / alphanull
11+
* @version 1.6.0
12+
* @license MIT
13+
*/var n={configure:a,publish:u,subscribe:l,unsubscribe:p,removePersistentMessage:d};const i={async:!0,handleExceptions:!1,lenientUnsubscribe:!1};let t=-1;const o=new Map,s=new Map,r=new Map;function c(e){"function"==typeof queueMicrotask?queueMicrotask(e):"function"==typeof Promise?Promise.resolve().then(e):setTimeout(e,0)}function f(e){return void 0===e}function a({async:e,handleExceptions:n,lenientUnsubscribe:t}={}){f(e)||(i.async=e),f(n)||(i.handleExceptions=n),f(t)||(i.lenientUnsubscribe=t)}function u(e,n,t={}){if(!0===t.persist&&r.set(e,{data:n,options:t}),e.indexOf("*")>-1)throw new Error("Publish topic cannot contain any wildcards.");const o=h(e.split("/"),n,t,s,e);let a;o.sort(((e,n)=>e.priority===n.priority?e.position-n.position:e.priority>n.priority?-1:1));const u=f(t.async)?i.async:t.async;for(;a=o.shift();)if(u)c(b.bind(null,a,e,n,t));else if(!1===b(a,e,n,t)&&!1!==t.cancelable)return!1;return!0}function l(e,n,a={}){const u=t+=1;if(f(e))throw new Error("Subscribe failed - undefined Topic.");if(e.includes("undefined"))throw new Error(`Subscribe for '${e}' failed - found 'undefined' in topic, this is almost always an error: ${u}`);if(f(n))throw new Error(`Subscribe for '${e}' failed - undefined Handler`);const l={token:u,topic:e,handler:n,options:a};if(o.set(u,l),g(e.split("/"),l,s),!0!==a.persist)return u;const p=new RegExp(`^${e.replace("*","(.+)")}(/.+)?$`);for(const[e,n]of r){if(e.match(p)){if(f(n.options.async)?i.async:n.options.async)c(b.bind(null,l,e,n.data,a));else if(!1===b(l,e,n.data,a)&&!0===a.cancelable)break}}return u}function p(e,n,t){const r=n===Boolean(n)?n:t,c=f(r)?i.lenientUnsubscribe:r,a=e=>{const n=o.get(e);if(f(n)){if(!0===c)return;throw new Error(`Unsubscribe failed. Did not find subscriber for token: ${e}`)}w(n.topic.split("/"),n,s),o.delete(e)};if(f(e)){if(!0===c)return;throw new Error("Unsubscribe failed. No Arguments specified.")}if(Array.isArray(e))e.forEach((e=>a(e)));else if(!isNaN(parseFloat(e))&&isFinite(e))a(e);else{if(f(n)){if(!0===c)return;throw new Error(`Unsubscribe failed. No handler for topic based unsubscribe specified ${e}`)}for(const[,i]of o)if(i.handler===n&&i.topic===e){w(e.split("/"),i,s),o.delete(i.token);break}}}function d(e){r.delete(e)}function b(e,n,t,s={}){if(!o.has(e.token))return;e.options.invocations>0&&(e.options.invocations-=1,e.options.invocations<1&&p(e.token));const{handler:r}=e;if(!0!==s.handleExceptions&&!0!==i.handleExceptions)return!0===e.options.topicArg?r(n,t):r(t,n);try{return!0===e.options.topicArg?r(n,t):r(t,n)}catch(e){window.console&&window.console.error&&window.console.error("Exception while executing publish handler: ",e)}}function h(e,n,t={},o,s,r=[]){const c=o.get("subscribers")||new Map,a=o.get("topics");for(const[,e]of c){const{condition:o,topicArg:c}=e.options;(f(o)||(!0===c?!0===o(s,n):!0===o(n,s)))&&(e.position=r.push(e),e.priority=e.options.priority||0,e.async=Boolean(t.async||e.options.async||i.async))}if(e.length&&a){const i=a.get(e[0]),o=a.get("*");f(o)&&f(i)||(f(o)||h(e.slice(1,e.length),n,t,o,s,r),f(i)||h(e.slice(1,e.length),n,t,i,s,r),e.shift())}return r}function g(e,n,i){const[t]=e;f(i.get("topics"))&&i.set("topics",new Map);const o=i.get("topics");let s=o.get(t);f(s)&&(s=new Map,o.set(t,s)),e.length<2?(f(s.get("subscribers"))&&s.set("subscribers",new Map),s.get("subscribers").set(n.token,n)):(e.shift(),g(e,n,s))}function w(e,n,i){const[t]=e,o=i.get("topics"),s=o.get(t),r=s.get("subscribers");e.length<2?(r.delete(n.token),0===r.size&&s.delete("subscribers")):(e.shift(),w(e,n,s)),s.has("topics")&&0===s.get("topics").size&&s.delete("topics"),0===o.get(t).size&&o.delete(t)}e.configure=a,e.default=n,e.publish=u,e.removePersistentMessage=d,e.subscribe=l,e.unsubscribe=p,Object.defineProperty(e,"__esModule",{value:!0})}));

dist/publisher.min.js

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@alphanull/publisher",
33
"license": "MIT",
4-
"version": "1.6.0",
4+
"version": "1.6.1",
55
"description": "Publisher is a JavaScript publish/subscribe library with many features, including: topic hierarchies, sync/async, priority, conditions, wildcards, persistent messages & more.",
66
"keywords": [
77
"publisher",

0 commit comments

Comments
 (0)