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 typings to get_store_value #5269

Merged
merged 5 commits into from
Sep 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

* Support `<slot slot="...">` ([#2079](https://github.com/sveltejs/svelte/issues/2079))
* Add types to `get` function in `svelte/store` ([#5269](https://github.com/sveltejs/svelte/pull/5269))
* Add `EventSource` to known globals ([#5463](https://github.com/sveltejs/svelte/issues/5463))
* Fix compiler exception with `~`/`+` combinators and `{...spread}` attributes ([#5465](https://github.com/sveltejs/svelte/issues/5465))

Expand Down
3 changes: 1 addition & 2 deletions src/compiler/compile/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { assign } from '../../runtime/internal/utils';
import Stats from '../Stats';
import parse from '../parse/index';
import render_dom from './render_dom/index';
Expand Down Expand Up @@ -68,7 +67,7 @@ function validate_options(options: CompileOptions, warnings: Warning[]) {
}

export default function compile(source: string, options: CompileOptions = {}) {
options = assign({ generate: 'dom', dev: false }, options);
options = Object.assign({ generate: 'dom', dev: false }, options);

const stats = new Stats();
const warnings = [];
Expand Down
6 changes: 4 additions & 2 deletions src/runtime/internal/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Readable } from "svelte/store";

export function noop() {}

export const identity = x => x;
Expand Down Expand Up @@ -60,7 +62,7 @@ export function subscribe(store, ...callbacks) {
return unsub.unsubscribe ? () => unsub.unsubscribe() : unsub;
}

export function get_store_value(store) {
export function get_store_value<T, S extends Readable<T>>(store: S): T {
let value;
subscribe(store, _ => value = _)();
return value;
Expand Down Expand Up @@ -158,4 +160,4 @@ export const has_prop = (obj, prop) => Object.prototype.hasOwnProperty.call(obj,

export function action_destroyer(action_result) {
return action_result && is_function(action_result.destroy) ? action_result.destroy : noop;
}
}