Skip to content

$store and store.subscribe behave differently #5520

Open
@BulatDashiev

Description

@BulatDashiev

Describe the bug
Open console in this repl
in synchronous for loop store.subscribe runs callback for each set, while reactive $: runs only on last set

const store = writable(0);
	
setTimeout(() => {
	for (let i = 1; i <= 10; ++i) {
		store.set(i); // syncronous set calls
	}
});
	
$: console.log('$:', $store); // logs only last value
store.subscribe(v => console.log('subscribe', v)); // logs each value

Expected behavior
Autosubscription and manual subscription should behave the same way or explained in documentation

Severity
Might broke some logic, if you expect all callback of set to run in autosubscription.
I think this should be clarified in documentation.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions