mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-04 18:34:02 +00:00
fix(maps): stop all delivery once the controller is destroyed
A listener could destroy the controller and re-subscribe one still pending in the snapshot, which then ran. Delivery now stops at destruction and a destroyed controller takes no listeners. Adds ordering tests for adds, duplicates and re-adds during delivery, and moves the current-state note after the section intro.
This commit is contained in:
1 parent
69a84c47a1
commit
b9fa0eedcc
3 files changed
+41
-3
No files matched your search
@@ -131,7 +131,8 @@ export class MapSourceController {
|
||||
* @returns {() => void} Unsubscribe.
|
||||
*/
|
||||
subscribe(listener) {
|
||||
if (typeof listener !== 'function') return () => {};
|
||||
// A destroyed controller never settles again, so it takes no listeners.
|
||||
if (typeof listener !== 'function' || this._destroyed) return () => {};
|
||||
this._subscribers.add(listener);
|
||||
return () => {
|
||||
this._subscribers.delete(listener);
|
||||
@@ -142,6 +143,7 @@ export class MapSourceController {
|
||||
if (this._destroyed || !this._subscribers.size) return;
|
||||
const state = this.getState();
|
||||
for (const listener of [...this._subscribers]) {
|
||||
if (this._destroyed) return;
|
||||
if (!this._subscribers.has(listener)) continue;
|
||||
try {
|
||||
listener(state);
|
||||
|
||||
Reference in new issue
Block a user