-
Notifications
You must be signed in to change notification settings - Fork 26
Description
Event listeners receive the beforeState and afterState as parameters, but these are incorrect when listening to a specific path and multiple events past events happened.
Reproduce Scenario
adobeDataLayer.push({"event": "zero", "data": "0" });
adobeDataLayer.push({"event": "one", "data": "1" });
adobeDataLayer.push({"event": "two", "data": "2" });
adobeDataLayer.addEventListener("one", function(event, beforeState, afterState) {
console.log(event, beforeState, afterState);
}, { "path": "data" });
// logs: {event: "one", data: "1"} "1" "1"
// should log: {event: "one", data: "1"} "0" "1"Proposed Resolution
I'd remove the beforeState and afterState state parameters of the event listener, because this seems a rather advanced feature that will be tricky to support correctly while making the data layer perform well and keep the script small. In theory this would be a breaking change, but these parameters are only passed when filtering with a path option, which in itself is another bug, at least from what is documented: "The state before the change caused by the event is available when the event object has data that modify the state." Therefore, it is unlikely that anybody already uses relies on that feature, and it should be safe to simplify the data layer by removing these parameters altogether.