From 767789235fbbfed29ee256621f2a171f04d29913 Mon Sep 17 00:00:00 2001 From: Julien Vincent Date: Sun, 14 May 2017 16:50:55 +0200 Subject: [PATCH 1/2] Introduced ability to declare a custom interpolator --- src/Interpolation.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Interpolation.js b/src/Interpolation.js index 315d596..8bf4784 100644 --- a/src/Interpolation.js +++ b/src/Interpolation.js @@ -24,7 +24,7 @@ export type InterpolationConfigType = { extrapolate?: ExtrapolateType; extrapolateLeft?: ExtrapolateType; extrapolateRight?: ExtrapolateType; -}; +} | (input: number) => number | string; var linear = (t) => t; @@ -35,6 +35,17 @@ var linear = (t) => t; class Interpolation { static create(config: InterpolationConfigType): (input: number) => number | string { + if (typeof config === 'function') { + const result = config(input); + + invariant( + typeof result === 'string' || typeof result === 'number', + 'Custom interpolator must return a string or a number' + ); + + return result; + } + if (config.outputRange && typeof config.outputRange[0] === 'string') { return createInterpolationFromStringOutputRange(config); } From 12ab5199f6b5c15a2ee68f018e299406e1f22ef3 Mon Sep 17 00:00:00 2001 From: Julien Vincent Date: Sun, 14 May 2017 17:29:50 +0200 Subject: [PATCH 2/2] fix: Interpolation.create expects a function --- src/Interpolation.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Interpolation.js b/src/Interpolation.js index 8bf4784..0a7fb33 100644 --- a/src/Interpolation.js +++ b/src/Interpolation.js @@ -36,14 +36,16 @@ class Interpolation { static create(config: InterpolationConfigType): (input: number) => number | string { if (typeof config === 'function') { - const result = config(input); + return (input: number) => { + const result = config(input); - invariant( - typeof result === 'string' || typeof result === 'number', - 'Custom interpolator must return a string or a number' - ); + invariant( + typeof result === 'string' || typeof result === 'number', + 'Custom interpolator must return a string or a number' + ); - return result; + return result; + }; } if (config.outputRange && typeof config.outputRange[0] === 'string') {