-
Notifications
You must be signed in to change notification settings - Fork 688
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: realtime updates failing in lists
- 2 components triggering unsubscriptions to the same event causing data to be outdated in atleast one component view - use composable to subscribe & add listeners for list updates - maintain subscribed doctypes in a reactive object so that doctype subscription event is emitted only once - remove doctype unsubscribe on onBeforeUnmount since ionic doesn't follow the usual component lifecycle - https://ionicframework.com/docs/vue/lifecycle & these ionic events are only available on IonPage and not the child components (cherry picked from commit 046b6c1)
- Loading branch information
1 parent
3ce285a
commit 7ccae18
Showing
3 changed files
with
26 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { reactive } from "vue" | ||
|
||
const subscribed = reactive({}) | ||
|
||
export function useListUpdate(socket, doctype, callback) { | ||
subscribe(socket, doctype) | ||
socket.on("list_update", (data) => { | ||
if (data.doctype == doctype) { | ||
callback(data.name) | ||
} | ||
}) | ||
} | ||
|
||
function subscribe(socket, doctype) { | ||
if (subscribed[doctype]) return | ||
|
||
socket.emit("doctype_subscribe", doctype) | ||
subscribed[doctype] = true | ||
} |