Node-Red configuration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

d3-dispatch.js 3.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // https://d3js.org/d3-dispatch/ v3.0.1 Copyright 2010-2021 Mike Bostock
  2. (function (global, factory) {
  3. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  4. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  5. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.d3 = global.d3 || {}));
  6. }(this, (function (exports) { 'use strict';
  7. var noop = {value: () => {}};
  8. function dispatch() {
  9. for (var i = 0, n = arguments.length, _ = {}, t; i < n; ++i) {
  10. if (!(t = arguments[i] + "") || (t in _) || /[\s.]/.test(t)) throw new Error("illegal type: " + t);
  11. _[t] = [];
  12. }
  13. return new Dispatch(_);
  14. }
  15. function Dispatch(_) {
  16. this._ = _;
  17. }
  18. function parseTypenames(typenames, types) {
  19. return typenames.trim().split(/^|\s+/).map(function(t) {
  20. var name = "", i = t.indexOf(".");
  21. if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
  22. if (t && !types.hasOwnProperty(t)) throw new Error("unknown type: " + t);
  23. return {type: t, name: name};
  24. });
  25. }
  26. Dispatch.prototype = dispatch.prototype = {
  27. constructor: Dispatch,
  28. on: function(typename, callback) {
  29. var _ = this._,
  30. T = parseTypenames(typename + "", _),
  31. t,
  32. i = -1,
  33. n = T.length;
  34. // If no callback was specified, return the callback of the given type and name.
  35. if (arguments.length < 2) {
  36. while (++i < n) if ((t = (typename = T[i]).type) && (t = get(_[t], typename.name))) return t;
  37. return;
  38. }
  39. // If a type was specified, set the callback for the given type and name.
  40. // Otherwise, if a null callback was specified, remove callbacks of the given name.
  41. if (callback != null && typeof callback !== "function") throw new Error("invalid callback: " + callback);
  42. while (++i < n) {
  43. if (t = (typename = T[i]).type) _[t] = set(_[t], typename.name, callback);
  44. else if (callback == null) for (t in _) _[t] = set(_[t], typename.name, null);
  45. }
  46. return this;
  47. },
  48. copy: function() {
  49. var copy = {}, _ = this._;
  50. for (var t in _) copy[t] = _[t].slice();
  51. return new Dispatch(copy);
  52. },
  53. call: function(type, that) {
  54. if ((n = arguments.length - 2) > 0) for (var args = new Array(n), i = 0, n, t; i < n; ++i) args[i] = arguments[i + 2];
  55. if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
  56. for (t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
  57. },
  58. apply: function(type, that, args) {
  59. if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
  60. for (var t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
  61. }
  62. };
  63. function get(type, name) {
  64. for (var i = 0, n = type.length, c; i < n; ++i) {
  65. if ((c = type[i]).name === name) {
  66. return c.value;
  67. }
  68. }
  69. }
  70. function set(type, name, callback) {
  71. for (var i = 0, n = type.length; i < n; ++i) {
  72. if (type[i].name === name) {
  73. type[i] = noop, type = type.slice(0, i).concat(type.slice(i + 1));
  74. break;
  75. }
  76. }
  77. if (callback != null) type.push({name: name, value: callback});
  78. return type;
  79. }
  80. exports.dispatch = dispatch;
  81. Object.defineProperty(exports, '__esModule', { value: true });
  82. })));