rusna
rusna

Reputation: 376

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.

Upvotes: 4

Views: 3024

Answers (3)

lithium
lithium

Reputation: 229

You can access the props, state and store with the official svelte browser extension

Upvotes: 0

Sandeep Gupta
Sandeep Gupta

Reputation: 7250

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

Upvotes: 4

Stephane Vanraes
Stephane Vanraes

Reputation: 16411

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

document.sveltestore = mystore;

this will work for svelte 1 & 2

Upvotes: 2

Related Questions