Skip to content

Hoist $store variables to the top scope of the referencing packaged file(s) #3637

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
btakita opened this issue Sep 29, 2019 · 1 comment
Closed
Labels
compiler Changes relating to the compiler temp-stale

Comments

@btakita
Copy link
Contributor

btakita commented Sep 29, 2019

A possible solution to #3636

Simply hoist the store value to the top of the packaged file scope. This can be achieved using subscribe & tracking each store variable referenced in a component with a unique name.

import { writable } from 'svelte/store'
let $store
const store = writable()
store.subscribe($ => $store = $)

Hoisting the store value will reduce the amount of subscribers to exported stores in other modules as well.


Somewhat related, but a design pattern I've used in modules is

import { writable } from 'svelte/store'
export let value
export __value = writable()
__value.subscribe($ => value = $)

I prefix stores with __ because the svelte compiler does not like variables with a $ prefix that it does not manage...

@btakita btakita changed the title Hoist $store variables to packaged file scope Hoist $store variables to the top scope of the referencing packaged file(s) Sep 29, 2019
@pngwn pngwn added compiler Changes relating to the compiler temp-stale and removed internals labels Jun 26, 2021
@dummdidumm
Copy link
Member

Closing since #3636 was fixed a while ago and it seems that this isse is a suggestion to fix #3636.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler Changes relating to the compiler temp-stale
Projects
None yet
Development

No branches or pull requests

4 participants