We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Add feature to automatically unsubscribe all nested subscriptions.
Currently, unsubscribing nested subscriptions is very verbose and error prone when forgetting to unsubscribe a nested subscribe call.
This is especially annoying when using something like react that needs cleanup.
let cleanupFunctions = []; const unsubscribeA = db.get("books").each(bookRef => { const unsubscribeB = bookRef.get("pages").each(pageRef => { const unsubscribeC = pageRef.on(console.log); cleanupFunctions.push(unsubscribeC); }); cleanupFunctions.push(unsubscribeB); }); cleanupFunctions.push(unsubscribeA); // Cleanup cleanupFunctions.forEach(fn => fn()); cleanupFunctions = [];
We could make this a lot simpler by allowing to unsubscribe all nested subscriptions:
const unsubscribe = db.get("books").each(bookRef => { bookRef.get("pages").each(pageRef => { pageRef.on(console.log); }); }); // Cleanup unsubscribe({ nested: true });
Or we can add a subscriptionContext that automatically unsubscribes every subscription inside the context:
const unsubscribe = db.subscriptionContext(ctx => { ctx.get("books").each(bookRef => { bookRef.get("pages").each(pageRef => { pageRef.on(console.log); }); }); });
This should probably be the default behavior.
We might add a flag to enable this as default behavior until the next major version is released, as this might be a breaking change.
The text was updated successfully, but these errors were encountered:
1d80cf4
Successfully merging a pull request may close this issue.
what
Add feature to automatically unsubscribe all nested subscriptions.
why
Currently, unsubscribing nested subscriptions is very verbose and error prone when forgetting to unsubscribe a nested subscribe call.
This is especially annoying when using something like react that needs cleanup.
We could make this a lot simpler by allowing to unsubscribe all nested subscriptions:
Or we can add a subscriptionContext that automatically unsubscribes every subscription inside the context:
This should probably be the default behavior.
We might add a flag to enable this as default behavior until the next major version is released, as this might be a breaking change.
The text was updated successfully, but these errors were encountered: