mirror of
https://github.com/sveltejs/svelte.git
synced 2024-12-01 17:30:59 +01:00
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>
This commit is contained in:
parent
85f882f23d
commit
f6ef6a9349
@ -98,7 +98,7 @@ export function writable<T>(value?: T, start: StartStopNotifier<T> = noop): Writ
|
||||
|
||||
return () => {
|
||||
subscribers.delete(subscriber);
|
||||
if (subscribers.size === 0) {
|
||||
if (subscribers.size === 0 && stop) {
|
||||
stop();
|
||||
stop = null;
|
||||
}
|
||||
|
@ -88,6 +88,14 @@ describe('store', () => {
|
||||
|
||||
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', () => {
|
||||
|
Loading…
Reference in New Issue
Block a user