Skip to content

Commit

Permalink
use workflow as exclusive source of truth for orders page
Browse files Browse the repository at this point in the history
Signed-off-by: Phil Prasek <prasek@gmail.com>
  • Loading branch information
prasek committed Sep 6, 2024
1 parent 02b55ab commit 34c82dc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
7 changes: 0 additions & 7 deletions src/lib/components/shipment-status.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@
export let id: string | undefined = undefined;
export let status = '';
if (id) {
const broadcaster = new BroadcastChannel(`shipment-${id}`);
broadcaster?.addEventListener('message', (event) => {
status = event.data;
});
}
const inactiveStatuses = ['pending', 'unavailable', 'cancelled', 'failed'];
const activeStatuses = ['booked', 'dispatched', 'delivered'];
Expand Down
12 changes: 12 additions & 0 deletions src/routes/shipments/[id]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@
$: {
if (shipment?.id) {
broadcaster = new BroadcastChannel(`shipment-${shipment.id}`);
//note: the customer order page is polling for order status from the workflow
//itself since this courier shipping page is
//not the only source of workflow state changes
//however to avoid polling on this this courier shipping page
//if multiple browser windows are open to the same shipping page
//we'd like those to be in sync, so will listen for events
//from a different browser window opened to the same shipping page
broadcaster?.addEventListener('message', (event) => {
status = event.data;
});
}
}
Expand Down

0 comments on commit 34c82dc

Please # to comment.