Skip to content

Incorrect before state event parameter for past events #96

@gabrielwalt

Description

@gabrielwalt

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugUnexpected problem or unintended behavior that impairs normal functioning.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions