From 32ccd4d3c8d09cb31edf7a844c112d86d6eb8d7a Mon Sep 17 00:00:00 2001 From: mg901 Date: Wed, 23 Jan 2019 11:47:18 +0300 Subject: [PATCH] refactor(make-breakpoints): change the output of the breakpoints breakpoints are not an array but an associative array BREAKING CHANGE: breakpoints are not an array but an associative array --- .../make-breakpoints-process.js | 43 ++++++++++--------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/src/make-breakpoints/make-breakpoints-process.js b/src/make-breakpoints/make-breakpoints-process.js index 89983bf..3fb7c17 100644 --- a/src/make-breakpoints/make-breakpoints-process.js +++ b/src/make-breakpoints/make-breakpoints-process.js @@ -1,5 +1,3 @@ -// @flow - import * as R from 'ramda'; import { toPxBreakValue } from './to-px-break-value'; import { basePropProcess } from './base-prop-process'; @@ -8,22 +6,27 @@ import { renameProp } from './rename-prop'; import { inheritProps } from './inherit-props'; import { calcRatioProcess } from './ratio-prop-utils'; import { setPropRoot } from './root-prop-utils'; -import { type Breakpoint } from '../models/breakpoints'; -import { type UserConfig } from '../models/user-config'; +import { makeBreaksMap } from './make-breaks-map'; + +const reduceIndexed = R.addIndex(R.reduce); -export const makeBreakpointsProcess = (config: UserConfig): Breakpoint[] => - createBreakpoints(config) - .map( - R.compose( - basePropProcess, - toPxBreakValue, - renameProp('breakpoint', 'value'), - ), - ) - .reduce(inheritProps, []) - .map( - R.compose( - setPropRoot, - calcRatioProcess, - ), - ); +// makeBreakpointsProcess :: Object -> {a: [Object]} +export const makeBreakpointsProcess = R.compose( + R.map(R.omit(['name'])), + R.reduce(makeBreaksMap, {}), + R.map( + R.compose( + setPropRoot, + calcRatioProcess, + ), + ), + reduceIndexed(inheritProps, []), + R.map( + R.compose( + basePropProcess, + toPxBreakValue, + renameProp('breakpoint', 'value'), + ), + ), + createBreakpoints, +);