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

Fixed cycle from #97 #98

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion src/array.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import value from "./value.js";
import { value } from "./value_object.js";
import numberArray, {isNumberArray} from "./numberArray.js";

export default function(a, b) {
Expand Down
3 changes: 1 addition & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export {default as interpolate} from "./value.js";
export {value as interpolate, object as interpolateObject} from "./value_object.js";
export {default as interpolateArray} from "./array.js";
export {default as interpolateBasis} from "./basis.js";
export {default as interpolateBasisClosed} from "./basisClosed.js";
Expand All @@ -7,7 +7,6 @@ export {default as interpolateDiscrete} from "./discrete.js";
export {default as interpolateHue} from "./hue.js";
export {default as interpolateNumber} from "./number.js";
export {default as interpolateNumberArray} from "./numberArray.js";
export {default as interpolateObject} from "./object.js";
export {default as interpolateRound} from "./round.js";
export {default as interpolateString} from "./string.js";
export {interpolateTransformCss, interpolateTransformSvg} from "./transform/index.js";
Expand Down
23 changes: 0 additions & 23 deletions src/object.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/piecewise.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {default as value} from "./value.js";
import { value } from "./value_object";

export default function piecewise(interpolate, values) {
if (values === undefined) values = interpolate, interpolate = value;
Expand Down
24 changes: 23 additions & 1 deletion src/value.js → src/value_object.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import string from "./string.js";
import constant from "./constant.js";
import numberArray, {isNumberArray} from "./numberArray.js";

export default function(a, b) {
export function value(a, b) {
var t = typeof b, c;
return b == null || t === "boolean" ? constant(b)
: (t === "number" ? number
Expand All @@ -20,3 +20,25 @@ export default function(a, b) {
: typeof b.valueOf !== "function" && typeof b.toString !== "function" || isNaN(b) ? object
: number)(a, b);
}

export function object(a, b) {
var i = {},
c = {},
k;

if (a === null || typeof a !== "object") a = {};
if (b === null || typeof b !== "object") b = {};

for (k in b) {
if (k in a) {
i[k] = value(a[k], b[k]);
} else {
c[k] = b[k];
}
}

return function(t) {
for (k in i) c[k] = i[k](t);
return c;
};
}