improve output size by reusing is_function

pull/5702/head
Ivan Hofer 5 years ago
parent 0d9a3b7209
commit 6063887469

@ -11,7 +11,7 @@ export function assign<T, S>(tar: T, src: S): T & S {
}
export function is_promise<T = any>(value: any): value is PromiseLike<T> {
return value && typeof value === 'object' && typeof value.then === 'function';
return value && typeof value === 'object' && is_function(value.then);
}
export function add_location(element, file, line, column, char) {
@ -33,7 +33,7 @@ export function is_function(thing: any): thing is Function {
}
export function safe_not_equal(a, b) {
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || is_function(a));
}
export function not_equal(a, b) {
@ -45,7 +45,7 @@ export function is_empty(obj) {
}
export function validate_store(store, name) {
if (store != null && typeof store.subscribe !== 'function') {
if (store != null && !is_function(store.subscribe)) {
throw new Error(`'${name}' is not a store with a 'subscribe' method`);
}
}

@ -1,5 +1,5 @@
import { Readable, writable } from 'svelte/store';
import { assign, loop, now, Task } from 'svelte/internal';
import { assign, is_function, loop, now, Task } from 'svelte/internal';
import { linear } from 'svelte/easing';
import { is_date } from './utils';
@ -111,7 +111,7 @@ export function tweened<T>(value?: T, defaults: Options<T> = {}): Tweened<T> {
if (!started) {
fn = interpolate(value, new_value);
if (typeof duration === 'function') duration = duration(value, new_value);
if (is_function(duration)) duration = duration(value, new_value);
started = true;
}

@ -186,7 +186,7 @@ export function draw(node: SVGElement & { getTotalLength(): number }, {
} else {
duration = len / speed;
}
} else if (typeof duration === 'function') {
} else if (is_function(duration)) {
duration = duration(len);
}

Loading…
Cancel
Save