throw, changelog

pull/7947/head
Simon Holthausen 3 years ago
parent 2656df7273
commit 85d45cb221

@ -10,9 +10,11 @@
* **breaking** Stricter types for `onMount` - now throws a type error when returning a function asynchronously to catch potential mistakes around callback functions (see PR for migration instructions) ([#8136](https://github.com/sveltejs/svelte/pull/8136)) * **breaking** Stricter types for `onMount` - now throws a type error when returning a function asynchronously to catch potential mistakes around callback functions (see PR for migration instructions) ([#8136](https://github.com/sveltejs/svelte/pull/8136))
* **breaking** Overhaul and drastically improve creating custom elements with Svelte (see PR for list of changes and migration instructions) ([#8457](https://github.com/sveltejs/svelte/pull/8457)) * **breaking** Overhaul and drastically improve creating custom elements with Svelte (see PR for list of changes and migration instructions) ([#8457](https://github.com/sveltejs/svelte/pull/8457))
* **breaking** Deprecate `SvelteComponentTyped`, use `SvelteComponent` instead ([#8512](https://github.com/sveltejs/svelte/pull/8512)) * **breaking** Deprecate `SvelteComponentTyped`, use `SvelteComponent` instead ([#8512](https://github.com/sveltejs/svelte/pull/8512))
* **breaking** Error on falsy values instead of stores passed to `derived` ([#7947](https://github.com/sveltejs/svelte/pull/7947))
* Add `a11y no-noninteractive-element-interactions` rule ([#8391](https://github.com/sveltejs/svelte/pull/8391)) * Add `a11y no-noninteractive-element-interactions` rule ([#8391](https://github.com/sveltejs/svelte/pull/8391))
* Add `a11y-no-static-element-interactions`rule ([#8251](https://github.com/sveltejs/svelte/pull/8251)) * Add `a11y-no-static-element-interactions`rule ([#8251](https://github.com/sveltejs/svelte/pull/8251))
* Bind `null` option and input values consistently ([#8312](https://github.com/sveltejs/svelte/issues/8312)) * Bind `null` option and input values consistently ([#8312](https://github.com/sveltejs/svelte/issues/8312))
* Allow `$store` to be used with changing values including nullish values ([#7555](https://github.com/sveltejs/svelte/issues/7555))
## Unreleased (3.0) ## Unreleased (3.0)

@ -164,10 +164,10 @@ export function derived<S extends Stores, T>(
export function derived<T>(stores: Stores, fn: Function, initial_value?: T): Readable<T> { export function derived<T>(stores: Stores, fn: Function, initial_value?: T): Readable<T> {
const single = !Array.isArray(stores); const single = !Array.isArray(stores);
const stores_array: Array<Readable<any>> = single const stores_array: Array<Readable<any>> = single ? [stores as Readable<any>] : stores as Array<Readable<any>>;
// Fall back to readable() for falsy stores in array, else derived store will be forever pending if (!stores_array.every(Boolean)) {
? [(stores || readable()) as Readable<any>] throw new Error('derived() expects stores as input, got a falsy value')
: (stores as Array<Readable<any>>).map(store => store || readable()); }
const auto = fn.length < 2; const auto = fn.length < 2;

@ -429,37 +429,19 @@ describe('store', () => {
assert.equal(b_started, false); assert.equal(b_started, false);
}); });
it('works with undefined stores #1', () => { it('errors on undefined stores #1', () => {
const a = derived(null, (n) => { assert.throws(() => {
return n; derived(null, (n) => n);
}); });
const values = [];
const unsubscribe = a.subscribe((value) => values.push(value));
unsubscribe();
assert.deepEqual(values, [undefined]);
}); });
it('works with undefined stores #2', () => { it('errors on undefined stores #2', () => {
const a = writable(1); assert.throws(() => {
const b = derived([a, null, undefined], ([n, un1, un2]) => { const a = writable(1);
assert.equal(un1, undefined); derived([a, null, undefined], ([n]) => {
assert.equal(un2, undefined); return n * 2;
return n * 2; });
});
const values = [];
const unsubscribe = b.subscribe(value => {
values.push(value);
}); });
a.set(2);
assert.deepEqual(values, [2, 4]);
unsubscribe();
a.set(3);
assert.deepEqual(values, [2, 4]);
}); });
}); });

Loading…
Cancel
Save