Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(data-events): unique event key #3659

Closed
wants to merge 4 commits into from

Conversation

miguelpeixe
Copy link
Member

All Submissions:

Changes proposed in this Pull Request:

Implement support for a unique event key to prevent multiple consecutive dispatches for events that always send the latest and complete payload in the same execution.

The key is determined when registering the action or listener:

Data_Events::register_action( 'my_action', 'email' );
// or:
Data_Events::register_listener( 'my_hook', 'my_action', 'my_callback', 'email' );

In the example above, events dispatched matching the value in the property email of its payload data will only be executed once with the final payload data:

Data_Events::dispatch( $action_name, [ 'email' => 'test@test.com', 'foo' => 'bar' ] );
Data_Events::dispatch( $action_name, [ 'email' => 'test@test.com', 'foo' => 'baz' ] );

Only 1 dispatch will be executed, containing [ 'email' => 'test@test.com', 'foo' => 'baz' ].

This PR depends on #3616

How to test the changes in this Pull Request:

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

Base automatically changed from feat/data-events-dispatch-shutdown to trunk January 8, 2025 22:27
@miguelpeixe
Copy link
Member Author

After some thought, this feature seems overkill and adds unnecessary complexity to data events. Each feature can handle their own deduplication to avoid consecutive requests or dispatches.

This is currently being done in Network's content distribution and soon we'll have something similar for ESP syncs.

@miguelpeixe miguelpeixe closed this Jan 9, 2025
@miguelpeixe miguelpeixe deleted the feat/data-events-unique-event-key branch January 9, 2025 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant