fix: don't throw when calling writable() unsubscribe twice (#8186)

Fixes one case of #4765

---------

Co-authored-by: Ben Bucksch <bbucksch@jw.org>
Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
Co-authored-by: Yuichiro Yamashita <xydybaseball@gmail.com>
pull/8314/head
Ben Bucksch 3 years ago committed by GitHub
parent 85f882f23d
commit f6ef6a9349
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -98,7 +98,7 @@ export function writable<T>(value?: T, start: StartStopNotifier<T> = noop): Writ
return () => { return () => {
subscribers.delete(subscriber); subscribers.delete(subscriber);
if (subscribers.size === 0) { if (subscribers.size === 0 && stop) {
stop(); stop();
stop = null; stop = null;
} }

@ -88,6 +88,14 @@ describe('store', () => {
unsubscribe(); unsubscribe();
}); });
it('no error even if unsubscribe calls twice', () => {
let num = 0;
const store = writable(num, set => set(num += 1));
const unsubscribe = store.subscribe(() => { });
unsubscribe();
assert.doesNotThrow(() => unsubscribe());
});
}); });
describe('readable', () => { describe('readable', () => {

Loading…
Cancel
Save