Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 625
rusna Avatar asked Nov 03 '25 07:11

rusna


2 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

like image 154
dasfdsa Avatar answered Nov 06 '25 01:11

dasfdsa


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

document.sveltestore = mystore;

this will work for svelte 1 & 2

like image 20
Stephane Vanraes Avatar answered Nov 06 '25 00:11

Stephane Vanraes



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!