Created
March 12, 2021 20:49
-
-
Save DeadWisdom/3fe297588b7b9a86849a80e18572b356 to your computer and use it in GitHub Desktop.
DataPack
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
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