Multiple App Instances with Stores #5186
SharadJ85
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
So by default, there are three ways in svelte that you can use to pass data around different components.
1. The obvious, by using Props
Pass data from a parent to a child.
2. Setting up and using Context
Can pass data from parent to any deep child component.
3. By using svelte Store
Can set,update & use/subscribe the data from/in any file or component.
storeVar.set()
sets either of the instance value depending on the page load time.storeVar.update()
sets the value from the last instance.Setup a svelte app to detect multiple custom embed codes from the root index file and run multiple instances of the App. The embed code will have additional data - video size, aspect ratio, etc. So each instance UI will change depending on the embedded code attributes(passed as props to App). On the UI, the user might click on different actions like screen sizes and accordingly, I'll have to update the App values(props passed from index to App) for that instance only and not others.
From the above issues, either I can't pass or update the values later in the components(issue 2.2, 2.3) OR the store doesn't save every instance value (3.1)
Basically, I created an array of objects with the instance
id
anddata
. Use update() instead of set(). I filter the new instance object from the array before adding the same instance's new data.package.json
Index.html
main.ts
helpers.ts
store.ts
App.svelte
any other component (get store instance value)
Let me know in the comments if you've found any issues with the above method OR know/used a better alternative for all this.
Note:
Beta Was this translation helpful? Give feedback.
All reactions