@xuda.io/xuda-worker-bundle 1.3.2615 → 1.3.2617
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/index.js +16 -8
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -208,16 +208,24 @@ func.runtime.platform.off = function (name, handler) {
|
|
|
208
208
|
handlers.splice(index, 1);
|
|
209
209
|
}
|
|
210
210
|
};
|
|
211
|
+
func.runtime.platform._emitting = {};
|
|
211
212
|
func.runtime.platform.emit = function (name, data) {
|
|
212
|
-
|
|
213
|
-
if (
|
|
214
|
-
|
|
215
|
-
|
|
213
|
+
// re-entrancy guard: prevent infinite loops when DOM bridge triggers the same event
|
|
214
|
+
if (func.runtime.platform._emitting[name]) return;
|
|
215
|
+
func.runtime.platform._emitting[name] = true;
|
|
216
|
+
try {
|
|
217
|
+
const handlers = func.runtime.platform._event_bus[name];
|
|
218
|
+
if (handlers) {
|
|
219
|
+
for (let i = 0; i < handlers.length; i++) {
|
|
220
|
+
handlers[i](data);
|
|
221
|
+
}
|
|
216
222
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
223
|
+
// also fire on DOM if in browser (for backward compatibility with $(document).on listeners)
|
|
224
|
+
if (func.runtime.platform.has_document() && typeof $ !== 'undefined') {
|
|
225
|
+
$(document).trigger(name, Array.isArray(data) ? data : [data]);
|
|
226
|
+
}
|
|
227
|
+
} finally {
|
|
228
|
+
func.runtime.platform._emitting[name] = false;
|
|
221
229
|
}
|
|
222
230
|
};
|
|
223
231
|
|