Is it possible to access the Svelte store from web console?

Viewed 1087

I'm debugging the Svelte app and wondering if it is possible to access svelte data in the store from the web console? Does somebody know if it is possible, if it yes, how pls :)

And by the way, we are still using svelte 1.

3 Answers

Following is a neat way to access store:

1.Define a property (ex: store) on window object and have its getter to log the store data.

Object.defineProperty(window, "store", {
    get : _ => {
        environmentV2.subscribe(e => console.log(e))
    }
});

2.Type store in your console and press enter. You will see the store data as follows:

enter image description here

During initialization you can assign the store to the document object:

document.sveltestore = mystore;

this will work for svelte 1 & 2

Related