Skip to content

What would be the best way of facilitating reactivity in classes from a library that is not for Svelte? #12915

Answered by brunnerh
webJose asked this question in Q&A
Discussion options

You must be logged in to vote

It's a function that is called when the value of the store is changed, before all the subscribers are executed.
It exists to prevent invalid intermediate states particularly when using derived stores.
Regular users are unlikely to need this, the argument should default to a noop.

In Svelte it is used like this:

const run_queue = !subscriber_queue.length;
for (const subscriber of subscribers) {
  subscriber[1](); // `invalidate` calls
  subscriber_queue.push(subscriber, value);
}
if (run_queue) {
  for (let i = 0; i < subscriber_queue.length; i += 2) {
    subscriber_queue[i][0](subscriber_queue[i + 1]); // `run` calls
  }
  subscriber_queue.length = 0;
}

A bit more info on this in my answ…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@webJose
Comment options

@brunnerh
Comment options

Answer selected by webJose
@webJose
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants