Skip to content

Commit

Permalink
feat: replace flattenArray with build-in Array.flat function
Browse files Browse the repository at this point in the history
Signed-off-by: Tobias Kuppens Groot <[email protected]>
  • Loading branch information
tkgroot committed Feb 11, 2022
1 parent 55a3a47 commit 66e31cc
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 9 deletions.
3 changes: 1 addition & 2 deletions src/animatables.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {

import {
is,
flattenArray,
filterArray,
toArray,
} from './helpers.js';
Expand All @@ -14,7 +13,7 @@ import {
} from './values.js';

export function parseTargets(targets) {
const targetsArray = targets ? (flattenArray(is.arr(targets) ? targets.map(toArray) : toArray(targets))) : [];
const targetsArray = targets ? (is.arr(targets) ? targets.map(toArray).flat() : toArray(targets).flat()) : [];
return filterArray(targetsArray, (item, pos, self) => self.indexOf(item) === pos);
}

Expand Down
1 change: 0 additions & 1 deletion src/anime.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
random,
is,
filterArray,
flattenArray,
toArray,
arrayContains,
cloneObject,
Expand Down
4 changes: 0 additions & 4 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ export function filterArray(arr, callback) {
return result;
}

export function flattenArray(arr) {
return arr.reduce((a, b) => a.concat(is.arr(b) ? flattenArray(b) : b), []);
}

export function toArray(o) {
if (is.arr(o)) return o;
if (is.str(o)) o = selectString(o) || o;
Expand Down
3 changes: 1 addition & 2 deletions src/keyframes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
is,
cloneObject,
mergeObjects,
flattenArray,
filterArray,
} from './helpers.js';

Expand Down Expand Up @@ -52,7 +51,7 @@ function convertPropertyValueToTweens(propertyValue, tweenSettings) {

function flattenParamsKeyframes(keyframes) {
const properties = {};
const propertyNames = filterArray(flattenArray(keyframes.map(key => Object.keys(key))), p => is.key(p))
const propertyNames = filterArray(keyframes.map((key) => Object.keys(key)).flat(), p => is.key(p))
.reduce((a,b) => {
if (a.indexOf(b) < 0) {
a.push(b);
Expand Down

0 comments on commit 66e31cc

Please sign in to comment.