Skip to content
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

Add state() method handling for components #1028

Merged
merged 1 commit into from
Dec 16, 2017
Merged

Add state() method handling for components #1028

merged 1 commit into from
Dec 16, 2017

Conversation

emilos
Copy link
Contributor

@emilos emilos commented Dec 15, 2017

Hey,

This PR is a proposal of API extension that would allow setting the Store inside of the top level component (previously discussed briefly in gitter).

import { Store } from 'svelte/store'
export default {
  store () {
    return new Store({ foo: 'bar' })
  }
}

The motivation for such change is making it easier to consume the component in other apps.

Instead of:

import Component from '@foo/bar'
import { Store } from 'svelte/store'

const store = new Store({ foo: 'bar' })
new Component({
  target: document.getElementById('foo'),
  store
})

it would become:

import Component from '@foo/bar'

new Component({
  target: document.getElementById('foo')
})

where the store would become an implementation detail instead.

Please let me know if there's anything missing (e.g. specs of some type) and I'll add :).

Thanks!

@codecov-io
Copy link

codecov-io commented Dec 15, 2017

Codecov Report

Merging #1028 into master will decrease coverage by 0.01%.
The diff coverage is 90%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #1028      +/-   ##
=========================================
- Coverage   92.01%     92%   -0.02%     
=========================================
  Files         119     119              
  Lines        4356    4363       +7     
  Branches     1402    1406       +4     
=========================================
+ Hits         4008    4014       +6     
  Misses        148     148              
- Partials      200     201       +1
Impacted Files Coverage Δ
src/validate/js/propValidators/index.ts 100% <ø> (ø) ⬆️
src/generators/Generator.ts 94.51% <100%> (+0.02%) ⬆️
src/generators/dom/index.ts 95.42% <100%> (+0.02%) ⬆️
src/generators/server-side-rendering/index.ts 95.83% <83.33%> (-1.23%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7d949a6...d398b34. Read the comment docs.

@Rich-Harris Rich-Harris merged commit b49e6da into sveltejs:master Dec 16, 2017
@Rich-Harris
Copy link
Member

Awesome, thanks so much!

Rich-Harris added a commit that referenced this pull request Dec 16, 2017
get store() to work with nested components in SSR compiler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants