@woosh/meep-engine 2.98.1 → 2.98.3

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/build/meep.cjs CHANGED
@@ -890,6 +890,13 @@ function m4_multiply(out, a, b) {
890
890
  out[15] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
891
891
  }
892
892
 
893
+ const SignalFlags = {
894
+ /**
895
+ * If set - signal will not invoke handlers when dispatched
896
+ */
897
+ Silent: 1
898
+ };
899
+
893
900
  /**
894
901
  *
895
902
  * @enum {number}
@@ -968,18 +975,6 @@ class SignalHandler {
968
975
  */
969
976
  SignalHandler.prototype.isSignalHandler = true;
970
977
 
971
- const SignalFlags = {
972
- /**
973
- * If set - signal will not invoke handlers when dispatched
974
- */
975
- Silent: 1,
976
- /**
977
- * Is set at the start of the dispatch and cleared at the end
978
- * @deprecated
979
- */
980
- Dispatching: 2
981
- };
982
-
983
978
  /**
984
979
  *
985
980
  * @author Alex Goldring
@@ -989,6 +984,7 @@ const SignalFlags = {
989
984
 
990
985
  /**
991
986
  * Common dispatch stack
987
+ * @readonly
992
988
  * @type {SignalHandler[]}
993
989
  */
994
990
  const dispatch_stack = [];
@@ -1001,40 +997,17 @@ let dispatch_stack_top = 0;
1001
997
  */
1002
998
  class Signal {
1003
999
  /**
1004
- * Event dispatcher dedicated to single event type
1005
- * @constructor
1006
- */
1007
- constructor() {
1008
- /**
1009
- * @private
1010
- * @type {SignalHandler[]}
1011
- */
1012
- this.handlers = [];
1013
-
1014
- /**
1015
- * Internal flag bitmask
1016
- * @private
1017
- * @type {number}
1018
- */
1019
- this.flags = 0;
1020
- }
1021
-
1022
- /**
1023
- * @deprecated
1024
- * @returns {boolean}
1000
+ * @private
1001
+ * @type {SignalHandler[]}
1025
1002
  */
1026
- get dispatching() {
1027
- return this.getFlag(SignalFlags.Dispatching);
1028
- }
1003
+ handlers = [];
1029
1004
 
1030
1005
  /**
1031
- * @deprecated
1032
- * @param {boolean} v
1006
+ * Internal flag bitmask
1007
+ * @private
1008
+ * @type {number}
1033
1009
  */
1034
- set dispatching(v) {
1035
- this.writeFlag(SignalFlags.Dispatching, v);
1036
- }
1037
-
1010
+ flags = 0;
1038
1011
 
1039
1012
  /**
1040
1013
  *
@@ -1096,14 +1069,15 @@ class Signal {
1096
1069
 
1097
1070
 
1098
1071
  /**
1099
- *
1100
- * @param {function} h
1072
+ * Checks if a given signal handler is present or not
1073
+ * @param {function} handler
1074
+ * @param {*} [thisArg] if not present, will not be considered
1101
1075
  * @returns {boolean}
1102
1076
  */
1103
- contains(h) {
1077
+ contains(handler, thisArg) {
1104
1078
  const handlers = this.handlers;
1105
1079
 
1106
- const i = findSignalHandlerIndexByHandle(handlers, h);
1080
+ const i = findSignalHandlerIndexByHandle(handlers, handler, thisArg);
1107
1081
 
1108
1082
  return i !== -1;
1109
1083
  }
@@ -1125,7 +1099,7 @@ class Signal {
1125
1099
  }
1126
1100
 
1127
1101
  /**
1128
- *
1102
+ * Handler will only be run once, it will be removed automatically after the first execution
1129
1103
  * @param {function} h
1130
1104
  * @param {*} [context]
1131
1105
  */
@@ -1172,7 +1146,10 @@ class Signal {
1172
1146
  }
1173
1147
 
1174
1148
  /**
1175
- * Remove all handlers
1149
+ * Remove all handlers.
1150
+ * Please note that this will remove even all handlers, irrespective of where they were added from. If another script is attaching to the same signal, using this method will potentially break that code.
1151
+ * For most use cases, prefer to use {@link remove} method instead, or make use of {@link SignalBinding} if you need to keep track of multiple handlers
1152
+ * NOTE: Consider this method to be unsafe, only use it when you understand the implications
1176
1153
  */
1177
1154
  removeAll() {
1178
1155
  const handlers = this.handlers;
@@ -1180,6 +1157,7 @@ class Signal {
1180
1157
  }
1181
1158
 
1182
1159
  /**
1160
+ * NOTE: because of polymorphic call-site nature of this method, it's always better for performance to use monomorphic methods like `send0`, `send1` etc.
1183
1161
  * @param {...*} args
1184
1162
  */
1185
1163
  dispatch(...args) {
@@ -1188,13 +1166,8 @@ class Signal {
1188
1166
  return;
1189
1167
  }
1190
1168
 
1191
- //mark dispatch process
1192
- this.setFlag(SignalFlags.Dispatching);
1193
-
1194
1169
  dispatchViaProxy(this.handlers, args);
1195
1170
 
1196
- //mark end of dispatch process
1197
- this.clearFlag(SignalFlags.Dispatching);
1198
1171
  }
1199
1172
 
1200
1173
  /**
@@ -1560,14 +1533,6 @@ class Signal {
1560
1533
  dispatch_stack_top = stack_pointer;
1561
1534
  }
1562
1535
 
1563
- /**
1564
- * @deprecated do not use
1565
- * @returns {boolean}
1566
- */
1567
- isDispatching() {
1568
- return this.getFlag(SignalFlags.Dispatching);
1569
- }
1570
-
1571
1536
  /**
1572
1537
  *
1573
1538
  * @param {Signal} other
@@ -1598,7 +1563,7 @@ Signal.prototype.isSignal = true;
1598
1563
  *
1599
1564
  * @param {SignalHandler[]} handlers
1600
1565
  * @param {function} f
1601
- * @param thisArg
1566
+ * @param {*} [thisArg]
1602
1567
  * @returns {number} index of the handler, or -1 if not found
1603
1568
  */
1604
1569
  function findSignalHandlerIndexByHandle(handlers, f, thisArg) {
@@ -68276,6 +68241,23 @@ class SignalBinding {
68276
68241
  this.#linked = false;
68277
68242
  this.signal.remove(this.handler, this.context);
68278
68243
  }
68244
+
68245
+ /**
68246
+ * Creates a {@link SignalBinding} and links it immediately. Utility method
68247
+ * @param {Signal} signal
68248
+ * @param {function} handler
68249
+ * @param {*} [context]
68250
+ * @return {SignalBinding}
68251
+ */
68252
+ static bind(
68253
+ signal, handler, context
68254
+ ) {
68255
+ const r = new SignalBinding(signal, handler, context);
68256
+
68257
+ r.link();
68258
+
68259
+ return r;
68260
+ }
68279
68261
  }
68280
68262
 
68281
68263
  /**