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

[Feature]: Send events to HTML contexts #5054

Open
kwvanderlinde opened this issue Nov 19, 2024 · 1 comment
Open

[Feature]: Send events to HTML contexts #5054

kwvanderlinde opened this issue Nov 19, 2024 · 1 comment
Labels
feature Adding functionality that adds value

Comments

@kwvanderlinde
Copy link
Collaborator

Describe the Problem

If a frame (or dialog or overlay) needs to reflect the current application state (e.g., current selection, etc), it's a bit painful to accomplish. The onChangeSelection event and similar won't notify the frame itself of the changes. Instead they invoke another macro that is then responsible for reacting to the change, which could involve pushing data to the frame or reloading the frame.

The Solution you'd like

When an onChangeSelection, onChangeImpersonated, onChangeToken, onChangeMap, or onInitiativeChange event is emitted (I think that's all of them), it is also sent as a JavaScript event to any open HTML frame, dialog, or overlay. The event would contain any pertinent details (e.g., selected token ID, current map ID, etc).

It would then be possible to react to such an event in JavaScript, e.g.:

window.addEventListener("onChangeSelection", event => {
	/* Handle it here. */
});

Alternatives that you've considered.

None.

Additional Context

No response

@kwvanderlinde kwvanderlinde added the feature Adding functionality that adds value label Nov 19, 2024
@kwvanderlinde
Copy link
Collaborator Author

I have a framework where I follow this pattern, but have to translate the events myself into JS events. It basically just uses runJSFunction() to inject code like this:

'use strict';
((key, detail) => {
	const event = new CustomEvent(key, { detail: detail });
	window.dispatchEvent(event);
}).call(null, /* event key */, /* event details */);

I don't know if that would be the "right" approach for a built-in equivalent, but it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Adding functionality that adds value
Projects
None yet
Development

No branches or pull requests

1 participant