From ab37dedeab7cc1832de4b9062f75bd0ab2a5ea81 Mon Sep 17 00:00:00 2001 From: Valerian Saliou Date: Fri, 17 May 2024 15:50:33 +0200 Subject: [PATCH] Fix --- lib/mirage.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/mirage.js b/lib/mirage.js index edbc662..add3dc9 100644 --- a/lib/mirage.js +++ b/lib/mirage.js @@ -297,18 +297,19 @@ Mirage.prototype.__doPostStream = function( } else { var dataPartObject = JSON.parse(dataPart); + // Acquire event name + // Important: add prefix if event streamed from Mirage is \ + // a reserved event (eg. 'error' becomes ':error'). + var eventName = (eventBlock || "data"); + + if (STREAM_RESERVED_EVENTS.includes(eventName) === true) { + eventName = (":" + eventName); + } + // Process at next event loop tick, as the 'data' event might \ // come out-of-order. setImmediate(function() { // Raise event (fallback to 'data' if no event block) - // Important: add prefix if event streamed from Mirage is \ - // a reserved event (eg. 'error' becomes ':error'). - var eventName = (eventBlock || "data"); - - if (STREAM_RESERVED_EVENTS.includes(eventName) === true) { - eventName = (":" + eventName); - } - emitter.emit(eventName, dataPartObject); }); }