Skip to content

Instantly share code, notes, and snippets.

@DeadWisdom
Created March 12, 2021 20:49
Show Gist options
  • Save DeadWisdom/3fe297588b7b9a86849a80e18572b356 to your computer and use it in GitHub Desktop.
Save DeadWisdom/3fe297588b7b9a86849a80e18572b356 to your computer and use it in GitHub Desktop.
DataPack
export class DataPack {
_subscriptions: Map<string, Function> = new Map();
subscribe(name, query, callback) {
this.unsubscribe(name);
this._subscriptions.set(name, query.onSnapshot(callback));
}
unsubscribe(name) {
let sub = this._subscriptions.get(name);
if (sub !== undefined) {
sub(); // Removes the sub
}
}
unsubscribeAll() {
this._subscriptions.forEach((value, key) => {});
this._subscriptions.clear();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment