Skip to content

Commit

Permalink
fix: Parameters with default values are optional
Browse files Browse the repository at this point in the history
  • Loading branch information
bfanger authored and Bob Fanger committed Jun 30, 2020
1 parent b56829c commit ecf81b9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 38 deletions.
6 changes: 3 additions & 3 deletions src/runtime/animate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ export interface AnimationConfig {
}

interface FlipParams {
delay: number;
duration: number | ((len: number) => number);
easing: (t: number) => number;
delay?: number;
duration?: number | ((len: number) => number);
easing?: (t: number) => number;
}

export function flip(node: Element, animation: { from: DOMRect; to: DOMRect }, params: FlipParams): AnimationConfig {
Expand Down
70 changes: 35 additions & 35 deletions src/runtime/transition/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ export interface TransitionConfig {
}

interface BlurParams {
delay: number;
duration: number;
delay?: number;
duration?: number;
easing?: EasingFunction;
amount: number;
opacity: number;
amount?: number;
opacity?: number;
}

export function blur(node: Element, {
Expand All @@ -25,7 +25,7 @@ export function blur(node: Element, {
easing = cubicInOut,
amount = 5,
opacity = 0
}: BlurParams): TransitionConfig {
}: BlurParams = {}): TransitionConfig {
const style = getComputedStyle(node);
const target_opacity = +style.opacity;
const f = style.filter === 'none' ? '' : style.filter;
Expand All @@ -41,16 +41,16 @@ export function blur(node: Element, {
}

interface FadeParams {
delay: number;
duration: number;
easing: EasingFunction;
delay?: number;
duration?: number;
easing?: EasingFunction;
}

export function fade(node: Element, {
delay = 0,
duration = 400,
easing = linear
}: FadeParams): TransitionConfig {
}: FadeParams = {}): TransitionConfig {
const o = +getComputedStyle(node).opacity;

return {
Expand All @@ -62,12 +62,12 @@ export function fade(node: Element, {
}

interface FlyParams {
delay: number;
duration: number;
easing: EasingFunction;
x: number;
y: number;
opacity: number;
delay?: number;
duration?: number;
easing?: EasingFunction;
x?: number;
y?: number;
opacity?: number;
}

export function fly(node: Element, {
Expand All @@ -77,7 +77,7 @@ export function fly(node: Element, {
x = 0,
y = 0,
opacity = 0
}: FlyParams): TransitionConfig {
}: FlyParams = {}): TransitionConfig {
const style = getComputedStyle(node);
const target_opacity = +style.opacity;
const transform = style.transform === 'none' ? '' : style.transform;
Expand All @@ -95,16 +95,16 @@ export function fly(node: Element, {
}

interface SlideParams {
delay: number;
duration: number;
easing: EasingFunction;
delay?: number;
duration?: number;
easing?: EasingFunction;
}

export function slide(node: Element, {
delay = 0,
duration = 400,
easing = cubicOut
}: SlideParams): TransitionConfig {
}: SlideParams = {}): TransitionConfig {
const style = getComputedStyle(node);
const opacity = +style.opacity;
const height = parseFloat(style.height);
Expand Down Expand Up @@ -133,11 +133,11 @@ export function slide(node: Element, {
}

interface ScaleParams {
delay: number;
duration: number;
easing: EasingFunction;
start: number;
opacity: number;
delay?: number;
duration?: number;
easing?: EasingFunction;
start?: number;
opacity?: number;
}

export function scale(node: Element, {
Expand All @@ -146,7 +146,7 @@ export function scale(node: Element, {
easing = cubicOut,
start = 0,
opacity = 0
}: ScaleParams): TransitionConfig {
}: ScaleParams = {}): TransitionConfig {
const style = getComputedStyle(node);
const target_opacity = +style.opacity;
const transform = style.transform === 'none' ? '' : style.transform;
Expand All @@ -166,18 +166,18 @@ export function scale(node: Element, {
}

interface DrawParams {
delay: number;
speed: number;
duration: number | ((len: number) => number);
easing: EasingFunction;
delay?: number;
speed?: number;
duration?: number | ((len: number) => number);
easing?: EasingFunction;
}

export function draw(node: SVGElement & { getTotalLength(): number }, {
delay = 0,
speed,
duration,
easing = cubicInOut
}: DrawParams): TransitionConfig {
}: DrawParams = {}): TransitionConfig {
const len = node.getTotalLength();

if (duration === undefined) {
Expand All @@ -199,9 +199,9 @@ export function draw(node: SVGElement & { getTotalLength(): number }, {
}

interface CrossfadeParams {
delay: number;
duration: number | ((len: number) => number);
easing: EasingFunction;
delay?: number;
duration?: number | ((len: number) => number);
easing?: EasingFunction;
}

type ClientRectMap = Map<any, { rect: ClientRect }>;
Expand All @@ -212,7 +212,7 @@ export function crossfade({ fallback, ...defaults }: CrossfadeParams & {
const to_receive: ClientRectMap = new Map();
const to_send: ClientRectMap = new Map();

function crossfade(from: ClientRect, node: Element, params: CrossfadeParams): TransitionConfig {
function crossfade(from: ClientRect, node: Element, params: CrossfadeParams = {}): TransitionConfig {
const {
delay = 0,
duration = d => Math.sqrt(d) * 30,
Expand Down

0 comments on commit ecf81b9

Please sign in to comment.