Skip to content

Commit

Permalink
fix subscription/processing handlers and WebChannels.sendMessageTo, c…
Browse files Browse the repository at this point in the history
…ompatibility with Stipple 0.28
  • Loading branch information
hhaensel committed Jan 29, 2025
1 parent 8818661 commit 73242c1
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions assets/js/channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

// Genie.AllWebChannels holds all the channels created by the initWebChannel function
Genie.AllWebChannels = [];
Genie.findWebchannel = function(channel) {
Genie.findWebChannel = function(channel) {
return this.AllWebChannels.find((app) => app.channel == channel);
}
Genie.findApp = function(channel) {
const webchannel = this.findWebchannel(channel);
const webchannel = this.findWebChannel(channel);
return (webchannel) ? webchannel.parent : this.AllWebChannels[0];
}
// Genie.WebChannels holds common handlers for all models
Expand All @@ -27,8 +27,8 @@ Genie.WebChannels.broadcastMessage = async (message, payload = {}) => {
}
};
Genie.WebChannels.sendMessageTo = async (channel, message, payload = {}) => {
var WebChannel = Genie.findApp(channel);
(WebChannel) || (WebChannel = GENIEMODEL.WebChannel);
var WebChannel = Genie.findWebChannel(channel);
(WebChannel) || (WebChannel = Genie.AllWebChannels[0]);
WebChannel.sendMessageTo(channel, message, payload);
}

Expand Down Expand Up @@ -337,17 +337,19 @@ function parse_payload(WebChannel, json_data) {
};

function process_payload(WebChannel, event) {
for (let i = 0; i < WebChannel.processingHandlers.length; i++) {
let f = WebChannel.processingHandlers[i];
const handlers = WebChannel.processingHandlers.concat(Genie.WebChannels.processingHandlers);
for (let i = 0; i < handlers.length; i++) {
let f = handlers[i];
if (typeof f === 'function') {
f(event);
}
}
};

function subscription_ready(WebChannel) {
for (let i = 0; i < WebChannel.subscriptionHandlers.length; i++) {
let f = WebChannel.subscriptionHandlers[i];
const handlers = WebChannel.subscriptionHandlers.concat(Genie.WebChannels.subscriptionHandlers);
for (let i = 0; i < handlers.length; i++) {
let f = handlers[i];
if (typeof f === 'function') {
f();
}
Expand Down Expand Up @@ -379,5 +381,7 @@ function isDev() {
}

// --------------- Initialize WebChannel ---------------

// Genie.WebChannels = Genie.initWebChannel();
// compatibilty with Stipple v0.28
if (window.CHANNEL !== undefined) {
Genie.initWebChannel(window.CHANNEL);
}

2 comments on commit 73242c1

@hhaensel
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/123993

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v5.32.0 -m "<description of version>" 73242c1c64beb6b7dc7158dc33aed3a80825b219
git push origin v5.32.0

Please sign in to comment.