From 6445914e0ad8bdefdf6506aca866a38ca6941378 Mon Sep 17 00:00:00 2001 From: brettm12345 Date: Sun, 19 Jan 2020 07:42:39 -0500 Subject: [PATCH 1/7] Added typescript support --- package.json | 17 +- src/@types/@hocs__with-debugger/index.d.ts | 6 + src/@types/@hocs__with-log/index.d.ts | 6 + src/ReactDream.js | 130 ----------- src/ReactDream.ts | 138 +++++++++++ src/createElementWithProps.js | 3 - src/createElementWithProps.tsx | 11 + src/index.js | 30 --- src/index.ts | 30 +++ src/internals/doAp.js | 2 - src/internals/doAp.ts | 6 + src/internals/doConcat.js | 12 - src/internals/doConcat.tsx | 17 ++ src/internals/doContramap.js | 15 -- src/internals/doContramap.tsx | 19 ++ src/internals/doMap.js | 2 - src/internals/doMap.ts | 4 + src/internals/doPromap.js | 7 - src/internals/doPromap.ts | 13 ++ src/internals/doRotate.js | 18 -- src/internals/doRotate.ts | 30 +++ src/internals/doScale.js | 18 -- src/internals/doScale.ts | 31 +++ src/internals/doTranslate.js | 38 ---- src/internals/doTranslate.ts | 52 +++++ src/internals/types.ts | 10 + ...ferentiallyTransparentFunctionComponent.js | 17 -- ...ferentiallyTransparentFunctionComponent.ts | 34 +++ src/partialApplication/addProps.js | 1 - src/partialApplication/addProps.ts | 5 + src/partialApplication/ap.js | 1 - src/partialApplication/ap.ts | 5 + src/partialApplication/chain.js | 1 - src/partialApplication/chain.ts | 5 + src/partialApplication/concat.js | 1 - src/partialApplication/concat.ts | 5 + src/partialApplication/contramap.js | 1 - src/partialApplication/contramap.ts | 5 + src/partialApplication/debug.js | 1 - src/partialApplication/debug.ts | 5 + src/partialApplication/defaultProps.js | 1 - src/partialApplication/defaultProps.ts | 5 + src/partialApplication/fork.js | 1 - src/partialApplication/fork.ts | 5 + src/partialApplication/log.js | 1 - src/partialApplication/log.ts | 5 + src/partialApplication/map.js | 1 - src/partialApplication/map.ts | 5 + src/partialApplication/name.js | 1 - src/partialApplication/name.ts | 5 + src/partialApplication/promap.js | 1 - src/partialApplication/promap.ts | 5 + src/partialApplication/propTypes.js | 1 - src/partialApplication/propTypes.ts | 5 + src/partialApplication/removeProps.js | 1 - src/partialApplication/removeProps.ts | 5 + src/partialApplication/rotate.js | 1 - src/partialApplication/rotate.ts | 5 + src/partialApplication/scale.js | 1 - src/partialApplication/scale.ts | 5 + src/partialApplication/style.js | 1 - src/partialApplication/style.ts | 5 + src/partialApplication/translate.js | 1 - src/partialApplication/translate.ts | 5 + src/styleFromProps.js | 8 - src/styleFromProps.ts | 17 ++ src/types.ts | 4 + src/withStyleFromProps.js | 4 - src/withStyleFromProps.ts | 6 + tsconfig.json | 36 +++ yarn.lock | 215 ++++++++++++------ 71 files changed, 720 insertions(+), 394 deletions(-) create mode 100644 src/@types/@hocs__with-debugger/index.d.ts create mode 100644 src/@types/@hocs__with-log/index.d.ts delete mode 100644 src/ReactDream.js create mode 100644 src/ReactDream.ts delete mode 100644 src/createElementWithProps.js create mode 100644 src/createElementWithProps.tsx delete mode 100644 src/index.js create mode 100644 src/index.ts delete mode 100644 src/internals/doAp.js create mode 100644 src/internals/doAp.ts delete mode 100644 src/internals/doConcat.js create mode 100644 src/internals/doConcat.tsx delete mode 100644 src/internals/doContramap.js create mode 100644 src/internals/doContramap.tsx delete mode 100644 src/internals/doMap.js create mode 100644 src/internals/doMap.ts delete mode 100644 src/internals/doPromap.js create mode 100644 src/internals/doPromap.ts delete mode 100644 src/internals/doRotate.js create mode 100644 src/internals/doRotate.ts delete mode 100644 src/internals/doScale.js create mode 100644 src/internals/doScale.ts delete mode 100644 src/internals/doTranslate.js create mode 100644 src/internals/doTranslate.ts create mode 100644 src/internals/types.ts delete mode 100644 src/isReferentiallyTransparentFunctionComponent.js create mode 100644 src/isReferentiallyTransparentFunctionComponent.ts delete mode 100644 src/partialApplication/addProps.js create mode 100644 src/partialApplication/addProps.ts delete mode 100644 src/partialApplication/ap.js create mode 100644 src/partialApplication/ap.ts delete mode 100644 src/partialApplication/chain.js create mode 100644 src/partialApplication/chain.ts delete mode 100644 src/partialApplication/concat.js create mode 100644 src/partialApplication/concat.ts delete mode 100644 src/partialApplication/contramap.js create mode 100644 src/partialApplication/contramap.ts delete mode 100644 src/partialApplication/debug.js create mode 100644 src/partialApplication/debug.ts delete mode 100644 src/partialApplication/defaultProps.js create mode 100644 src/partialApplication/defaultProps.ts delete mode 100644 src/partialApplication/fork.js create mode 100644 src/partialApplication/fork.ts delete mode 100644 src/partialApplication/log.js create mode 100644 src/partialApplication/log.ts delete mode 100644 src/partialApplication/map.js create mode 100644 src/partialApplication/map.ts delete mode 100644 src/partialApplication/name.js create mode 100644 src/partialApplication/name.ts delete mode 100644 src/partialApplication/promap.js create mode 100644 src/partialApplication/promap.ts delete mode 100644 src/partialApplication/propTypes.js create mode 100644 src/partialApplication/propTypes.ts delete mode 100644 src/partialApplication/removeProps.js create mode 100644 src/partialApplication/removeProps.ts delete mode 100644 src/partialApplication/rotate.js create mode 100644 src/partialApplication/rotate.ts delete mode 100644 src/partialApplication/scale.js create mode 100644 src/partialApplication/scale.ts delete mode 100644 src/partialApplication/style.js create mode 100644 src/partialApplication/style.ts delete mode 100644 src/partialApplication/translate.js create mode 100644 src/partialApplication/translate.ts delete mode 100644 src/styleFromProps.js create mode 100644 src/styleFromProps.ts create mode 100644 src/types.ts delete mode 100644 src/withStyleFromProps.js create mode 100644 src/withStyleFromProps.ts create mode 100644 tsconfig.json diff --git a/package.json b/package.json index f5e6c5a..f0ed086 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,15 @@ { - "name": "react-dream", - "version": "0.5.1", + "name": "@brettm12345/react-dream", + "version": "0.5.2", "description": "Fantasy Land type for React Components", "main": "dist/index.js", + "types": "dist/index.d.ts", "files": [ "dist" ], "scripts": { - "dist": "babel src/ -d dist/ --ignore spec.js", + "build": "tsc", + "dist": "tsc", "prepublishOnly": "npm run dist", "test": "babel-node test" }, @@ -29,6 +31,7 @@ "url": "https://github.com/xaviervia/react-dream/issues" }, "homepage": "https://github.com/xaviervia/react-dream#readme", + "private": false, "devDependencies": { "@klarna/higher-order-components": "^3.0.1", "babel-cli": "^6.24.1", @@ -37,7 +40,7 @@ "babel-preset-stage-3": "^6.24.1", "jsdom": "^11.12.0", "jsdom-global": "^3.0.2", - "prettier": "^1.5.3", + "prettier": "^1.19.1", "ramda": "^0.25.0", "react": "^16.0.0", "react-test-renderer": "^16.0.0", @@ -50,6 +53,10 @@ }, "dependencies": { "@hocs/with-debugger": "^0.1.0", - "@hocs/with-log": "^0.1.0" + "@hocs/with-log": "^0.1.0", + "@types/react": "^16.9.17", + "@types/recompose": "^0.30.7", + "fp-ts": "^2.4.1", + "typescript": "^3.7.5" } } diff --git a/src/@types/@hocs__with-debugger/index.d.ts b/src/@types/@hocs__with-debugger/index.d.ts new file mode 100644 index 0000000..f68ab1b --- /dev/null +++ b/src/@types/@hocs__with-debugger/index.d.ts @@ -0,0 +1,6 @@ +import { Hoc } from "src/types"; + +declare module "@hocs/with-debugger" { + const hoc: Hoc; + export default hoc; +} diff --git a/src/@types/@hocs__with-log/index.d.ts b/src/@types/@hocs__with-log/index.d.ts new file mode 100644 index 0000000..4df8b1b --- /dev/null +++ b/src/@types/@hocs__with-log/index.d.ts @@ -0,0 +1,6 @@ +import { Hoc } from "@hocs/with-debugger/node_modules/src/types"; + +declare module "@hocs/with-log" { + const hoc:

(messageFromProps: (props: P) => string) => Hoc

; + export default hoc; +} diff --git a/src/ReactDream.js b/src/ReactDream.js deleted file mode 100644 index a57cf39..0000000 --- a/src/ReactDream.js +++ /dev/null @@ -1,130 +0,0 @@ -import compose from 'recompose/compose' -import setDisplayName from 'recompose/setDisplayName' -import recomposeDefaultProps from 'recompose/defaultProps' -import setPropTypes from 'recompose/setPropTypes' -import withDebugger from '@hocs/with-debugger' -import withLog from '@hocs/with-log' -import doAp from './internals/doAp' -import doConcat from './internals/doConcat' -import doContramap from './internals/doContramap' -import doMap from './internals/doMap' -import doPromap from './internals/doPromap' -import doRotate from './internals/doRotate' -import doTranslate from './internals/doTranslate' -import doScale from './internals/doScale' -import styleFromProps from './styleFromProps' - -// ALGEBRAS -// ////////////////////////////////////////////////////////////////////////// // - -// ap : higherOrderComponent -> ReactDream -> ReactDream -const ap = higherOrderComponent => ReactDreamComponent => - ReactDream(doAp(higherOrderComponent)(ReactDreamComponent)) - -// chain : Component -> (Component -> ReactDream) -> ReactDream -const chain = Component => kleisliReactDreamComponent => kleisliReactDreamComponent(Component) - -// map : Component -> (Component -> Component) -> ReactDream -const map = Component => higherOrderComponent => ReactDream(doMap(higherOrderComponent)(Component)) - -// concat : Component -> Component -> ReactDream -const concat = Component => OtherComponent => - ReactDream(doConcat(OtherComponent.Component)(Component)) - -// contramap : Component -> (a -> Props) -> ReactDream -const contramap = Component => propsPreprocessor => - ReactDream(doContramap(propsPreprocessor)(Component)) - -// promap : Component -> (a -> Props) -> (Component -> Component) -> ReactDream -const promap = Component => (propsPreprocessor, higherOrderComponent) => - ReactDream(doPromap(propsPreprocessor, higherOrderComponent)(Component)) - -// CUSTOM HELPERS -// ////////////////////////////////////////////////////////////////////////// // - -// addProps : Component -> (Props -> Props) -> ReactDream -const addProps = Component => getPropsToAdd => - contramap(Component)(props => ({ - ...getPropsToAdd(props), - ...props, - })) - -// fork : Component -> (Component -> a) -> a -const fork = Component => extractComponent => extractComponent(Component) - -// debug : Component -> () -> IO ReactDream -const debug = Component => () => ReactDream(withDebugger(Component)) - -// defaultProps : Component -> (Props) -> ReactDream -const defaultProps = Component => props => ReactDream(recomposeDefaultProps(props)(Component)) - -// log : Component -> (Props -> String) -> IO ReactDream -const log = Component => messageFromProps => ReactDream(withLog(messageFromProps)(Component)) - -// name : Component -> String -> ReactDream -const name = Component => compose(map(Component), setDisplayName) - -// removeProps : Component -> (...Array) -> ReactDream -const removeProps = Component => (...propsToRemove) => - contramap(Component)(props => { - // Nasty but efficient - const propsCopy = { ...props } - propsToRemove.forEach(propName => { - delete propsCopy[propName] - }) - return propsCopy - }) - -// propTypes : Component -> (PropTypes) -> ReactDream -const propTypes = Component => propTypesToSet => ReactDream(setPropTypes(propTypesToSet)(Component)) - -// translate : Component -> (Props -> [Number]) -> ReactDream -const translate = Component => getTranslateFromProps => - ReactDream(doTranslate(getTranslateFromProps)(Component)) - -// rotate : Component -> (Props -> Number) -> ReactDream -const rotate = Component => getRotateFromProps => - ReactDream(doRotate(getRotateFromProps)(Component)) - -// scale : Component -> (Props -> Number) -> ReactDream -const scale = Component => getScaleFromProps => ReactDream(doScale(getScaleFromProps)(Component)) - -// style : Component -> (Props -> Style) -> ReactDream -const style = Component => getStyleFromProps => - contramap(Component)(styleFromProps(getStyleFromProps)) - -// TYPE -// ////////////////////////////////////////////////////////////////////////// // - -// ReactDream : Component -> ReactDream -const ReactDream = Component => ({ - Component, - - // Algebras - ap: ap(Component), - chain: chain(Component), - concat: concat(Component), - contramap: contramap(Component), - map: map(Component), - promap: promap(Component), - - // Custom helpers - addProps: addProps(Component), - debug: debug(Component), - defaultProps: defaultProps(Component), - fork: fork(Component), - name: name(Component), - log: log(Component), - propTypes: propTypes(Component), - removeProps: removeProps(Component), - rotate: rotate(Component), - scale: scale(Component), - style: style(Component), - translate: translate(Component), -}) - -ReactDream.of = ReactDream - -export const of = ReactDream.of - -export default ReactDream diff --git a/src/ReactDream.ts b/src/ReactDream.ts new file mode 100644 index 0000000..227f6e7 --- /dev/null +++ b/src/ReactDream.ts @@ -0,0 +1,138 @@ +import setDisplayName from "recompose/setDisplayName"; +import recomposeDefaultProps from "recompose/defaultProps"; +import setPropTypes from "recompose/setPropTypes"; +import { flow, Endomorphism } from "fp-ts/lib/function"; +import withDebugger from "@hocs/with-debugger"; +import withLog from "@hocs/with-log"; +import doAp from "./internals/doAp"; +import doConcat from "./internals/doConcat"; +import doContramap from "./internals/doContramap"; +import doMap from "./internals/doMap"; +import doPromap from "./internals/doPromap"; +import doRotate from "./internals/doRotate"; +import doTranslate from "./internals/doTranslate"; +import doScale from "./internals/doScale"; +import styleFromProps from "./styleFromProps"; +import { ComponentType, ValidationMap, CSSProperties } from "react"; +import { IO } from "fp-ts/lib/IO"; +import { Hoc } from "./types"; + +// ALGEBRAS +// ////////////////////////////////////////////////////////////////////////// // + +interface EnhancedProps { + style?: { + transform?: string; + }; +} + +export interface ReactDream

{ + Component: ComponentType

; + + // ap : higherOrderComponent -> ReactDream -> ReactDream + ap: (hoc: Hoc

) => ReactDream

; + + // chain : Component -> (Component -> ReactDream) -> ReactDream + chain: ( + toDream: (Component: ComponentType

) => ReactDream

+ ) => ReactDream

; + + // map : Component -> (Component -> Component) -> ReactDream + map: (hoc: Hoc

) => ReactDream

; + + // concat : ReactDream -> Component -> ReactDream + concat: (OtherComponent: ReactDream

) => ReactDream

; + + // contramap : Component -> (a -> Props) -> ReactDream + contramap: ( + propsPreprocessor: (props: P) => Props + ) => ReactDream

; + + // promap : Component -> (a -> Props) -> (Component -> Component) -> ReactDream + promap: (propsPreprocessor: (props: P) => P, hoc: Hoc

) => ReactDream

; + + // addProps : Component -> (Props -> Props) -> ReactDream + addProps: (getPropsToAdd: Endomorphism

) => ReactDream

; + + // fork : Component -> (Component -> a) -> a + fork: (extractComponent: (Component: ComponentType

) => A) => A; + + // debug : Component -> () -> IO ReactDream + debug: IO>; + + // defaultProps : Component -> (Props) -> ReactDream + defaultProps: (props: P) => ReactDream

; + + // log : Component -> (Props -> String) -> IO ReactDream + log: (messageFromProps: (props: P) => string) => ReactDream

; + + // name : Component -> String -> ReactDream + name: (name: string) => ReactDream

; + + // removeProps : Component -> (...Array) -> ReactDream + removeProps: (...propsToRemove: Array) => ReactDream

; + + // propTypes : Component -> (PropTypes) -> ReactDream + propTypes: (propTypes: ValidationMap

) => ReactDream

; + + // rotate : Component -> (Props -> Number) -> ReactDream + rotate: (getRotateFromProps: (props: P) => number) => ReactDream

; + + // scale : Component -> (Props -> Number) -> ReactDream + scale: (getScaleFromProps: (props: P) => number) => ReactDream

; + + // style : Component -> (Props -> Style) -> ReactDream + style: (getStyleFromProps: (props: P) => CSSProperties) => ReactDream

; + + // translate : Component -> (Props -> [Number]) -> ReactDream + translate: (getTranslateFromProps: (props: P) => number[]) => ReactDream

; +} + +const ReactDream =

(Component: ComponentType

): ReactDream

=> ({ + Component, + ap: hoc => ReactDream(doAp(hoc)(ReactDream(Component))), + chain: toDream => toDream(Component), + map: hoc => ReactDream(doMap(hoc)(Component)), + concat: OtherComponent => + ReactDream(doConcat(OtherComponent.Component)(Component)), + contramap: propsPreprocessor => + ReactDream(doContramap(propsPreprocessor)(Component)), + promap: (propsPreprocessor, hoc) => + ReactDream(doPromap(propsPreprocessor, hoc)(Component)), + addProps: getPropsToAdd => + ReactDream(Component).contramap(props => ({ + ...getPropsToAdd(props), + ...props + })), + fork: extractComponent => extractComponent(Component), + debug: () => ReactDream(withDebugger(Component)), + defaultProps: props => + ReactDream( + (recomposeDefaultProps(props)(Component) as unknown) as ComponentType

+ ), + name: flow(setDisplayName, ReactDream(Component).map), + log: messageFromProps => ReactDream(withLog(messageFromProps)(Component)), + removeProps: (...propsToRemove) => + ReactDream(Component).contramap(props => { + // Nasty but efficient + const propsCopy = { ...props }; + propsToRemove.forEach(propName => { + delete propsCopy[propName]; + }); + return propsCopy; + }), + propTypes: propTypesToSet => + ReactDream(setPropTypes(propTypesToSet)(Component)), + scale: getScaleFromProps => ReactDream(doScale(getScaleFromProps)(Component)), + translate: getTranslateFromProps => + ReactDream(doTranslate(getTranslateFromProps)(Component)), + rotate: getRotateFromProps => + ReactDream(doRotate(getRotateFromProps)(Component)), + style: getStyleFromProps => + ReactDream(Component).contramap(styleFromProps(getStyleFromProps)) +}); + +// TYPE +// ////////////////////////////////////////////////////////////////////////// // + +export default ReactDream; diff --git a/src/createElementWithProps.js b/src/createElementWithProps.js deleted file mode 100644 index 1c61706..0000000 --- a/src/createElementWithProps.js +++ /dev/null @@ -1,3 +0,0 @@ -import React from 'react' - -export default props => Component => diff --git a/src/createElementWithProps.tsx b/src/createElementWithProps.tsx new file mode 100644 index 0000000..8d91319 --- /dev/null +++ b/src/createElementWithProps.tsx @@ -0,0 +1,11 @@ +import React, { ComponentType, ReactElement } from "react"; + +type CreateElementWithProps =

( + props: P +) => (Component: ComponentType

) => ReactElement; + +const createElementWithProps: CreateElementWithProps = props => Component => ( + +); + +export default createElementWithProps; diff --git a/src/index.js b/src/index.js deleted file mode 100644 index 5d1225d..0000000 --- a/src/index.js +++ /dev/null @@ -1,30 +0,0 @@ -import ReactDream from './ReactDream' - -export { default as createElementWithProps } from './createElementWithProps' - -export { default as styleFromProps } from './styleFromProps' - -export { default as withStyleFromProps } from './withStyleFromProps' - -export { default as addProps } from './partialApplication/addProps' -export { default as ap } from './partialApplication/ap' -export { default as chain } from './partialApplication/chain' -export { default as concat } from './partialApplication/concat' -export { default as contramap } from './partialApplication/contramap' -export { default as debug } from './partialApplication/debug' -export { default as defaultProps } from './partialApplication/defaultProps' -export { default as fork } from './partialApplication/fork' -export { default as log } from './partialApplication/log' -export { default as map } from './partialApplication/map' -export { default as name } from './partialApplication/name' -export { default as promap } from './partialApplication/promap' -export { default as propTypes } from './partialApplication/propTypes' -export { default as removeProps } from './partialApplication/removeProps' -export { default as rotate } from './partialApplication/rotate' -export { default as scale } from './partialApplication/scale' -export { default as style } from './partialApplication/style' -export { default as translate } from './partialApplication/translate' - -export const of = ReactDream - -export default ReactDream diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..dab2aaf --- /dev/null +++ b/src/index.ts @@ -0,0 +1,30 @@ +import ReactDream from "./ReactDream"; + +export { default as createElementWithProps } from "./createElementWithProps"; + +export { default as styleFromProps } from "./styleFromProps"; + +export { default as withStyleFromProps } from "./withStyleFromProps"; + +export { default as addProps } from "./partialApplication/addProps"; +export { default as ap } from "./partialApplication/ap"; +export { default as chain } from "./partialApplication/chain"; +export { default as concat } from "./partialApplication/concat"; +export { default as contramap } from "./partialApplication/contramap"; +export { default as debug } from "./partialApplication/debug"; +export { default as defaultProps } from "./partialApplication/defaultProps"; +export { default as fork } from "./partialApplication/fork"; +export { default as log } from "./partialApplication/log"; +export { default as map } from "./partialApplication/map"; +export { default as name } from "./partialApplication/name"; +export { default as promap } from "./partialApplication/promap"; +export { default as propTypes } from "./partialApplication/propTypes"; +export { default as removeProps } from "./partialApplication/removeProps"; +export { default as rotate } from "./partialApplication/rotate"; +export { default as scale } from "./partialApplication/scale"; +export { default as style } from "./partialApplication/style"; +export { default as translate } from "./partialApplication/translate"; + +export const of = ReactDream; + +export default ReactDream; diff --git a/src/internals/doAp.js b/src/internals/doAp.js deleted file mode 100644 index e45900a..0000000 --- a/src/internals/doAp.js +++ /dev/null @@ -1,2 +0,0 @@ -// doAp : (Component -> Component) -> ReactDream -> Component -export default higherOrderComponent => DreamComponent => DreamComponent.fork(higherOrderComponent) diff --git a/src/internals/doAp.ts b/src/internals/doAp.ts new file mode 100644 index 0000000..c6dcd70 --- /dev/null +++ b/src/internals/doAp.ts @@ -0,0 +1,6 @@ +import { ReactDream } from "src/ReactDream"; +import { Hoc } from "src/types"; + +// doAp : (Component -> Component) -> ReactDream -> Component +export default

(hoc: Hoc

) => (DreamComponent: ReactDream

) => + DreamComponent.fork(hoc); diff --git a/src/internals/doConcat.js b/src/internals/doConcat.js deleted file mode 100644 index 95cc617..0000000 --- a/src/internals/doConcat.js +++ /dev/null @@ -1,12 +0,0 @@ -import React, { Fragment } from 'react' -import getDisplayName from 'recompose/getDisplayName' -import setDisplayName from 'recompose/setDisplayName' - -// doConcat : Component -> Component -> Component -export default ComponentA => ComponentB => - setDisplayName( - getDisplayName(ComponentB).concat(getDisplayName(ComponentA)) - )(props => - - - ) diff --git a/src/internals/doConcat.tsx b/src/internals/doConcat.tsx new file mode 100644 index 0000000..3a45157 --- /dev/null +++ b/src/internals/doConcat.tsx @@ -0,0 +1,17 @@ +import React, { Fragment, ComponentType, FC } from "react"; +import getDisplayName from "recompose/getDisplayName"; +import setDisplayName from "recompose/setDisplayName"; + +// doConcat : Component -> Component -> Component +type DoConcat =

(a: ComponentType

) => (b: ComponentType

) => FC

; +const doConcat: DoConcat = ComponentA => ComponentB => + setDisplayName(getDisplayName(ComponentB).concat(getDisplayName(ComponentA)))( + props => ( + + + + + ) + ); + +export default doConcat; diff --git a/src/internals/doContramap.js b/src/internals/doContramap.js deleted file mode 100644 index 32e0a7d..0000000 --- a/src/internals/doContramap.js +++ /dev/null @@ -1,15 +0,0 @@ -import React from 'react' -import compose from 'recompose/compose' -import getDisplayName from 'recompose/getDisplayName' -import isReferentiallyTransparentFunctionComponent from '../isReferentiallyTransparentFunctionComponent' - -// doContramap : (a -> Props) -> Component -> Component -export default propsPreprocessor => Component => { - const Enhanced = isReferentiallyTransparentFunctionComponent(Component) - ? compose(Component, propsPreprocessor) - : props => - - Enhanced.displayName = getDisplayName(Component) - - return Enhanced -} diff --git a/src/internals/doContramap.tsx b/src/internals/doContramap.tsx new file mode 100644 index 0000000..8ca9c5b --- /dev/null +++ b/src/internals/doContramap.tsx @@ -0,0 +1,19 @@ +import React, { ComponentType } from "react"; +import compose from "recompose/compose"; +import getDisplayName from "recompose/getDisplayName"; +import isReferentiallyTransparentFunctionComponent from "../isReferentiallyTransparentFunctionComponent"; + +// doContramap : (a -> Props) -> Component -> Component +const doContramap = ( + propsPreprocessor: (props: Outer) => Inner +) => (Component: ComponentType) => { + const Enhanced = isReferentiallyTransparentFunctionComponent(Component) + ? compose(Component, propsPreprocessor) + : (props: Outer) => ; + + (Enhanced as ComponentType).displayName = getDisplayName(Component); + + return Enhanced as ComponentType; +}; + +export default doContramap; diff --git a/src/internals/doMap.js b/src/internals/doMap.js deleted file mode 100644 index 395b071..0000000 --- a/src/internals/doMap.js +++ /dev/null @@ -1,2 +0,0 @@ -// (Component -> Component) -> Component -> Component -export default higherOrderComponent => Component => higherOrderComponent(Component) diff --git a/src/internals/doMap.ts b/src/internals/doMap.ts new file mode 100644 index 0000000..5bf1bf6 --- /dev/null +++ b/src/internals/doMap.ts @@ -0,0 +1,4 @@ +// (Component -> Component) -> Component -> Component +export default (higherOrderComponent: (component: C) => C) => ( + Component: C +) => higherOrderComponent(Component); diff --git a/src/internals/doPromap.js b/src/internals/doPromap.js deleted file mode 100644 index afa6e6c..0000000 --- a/src/internals/doPromap.js +++ /dev/null @@ -1,7 +0,0 @@ -import compose from 'recompose/compose' -import doContramap from './doContramap' -import doMap from './doMap' - -// doPromap : ((a -> Props), (Component -> Component)) -> Component -> Component -export default (propsPreprocessor, higherOrderComponent) => - compose(doMap(higherOrderComponent), doContramap(propsPreprocessor)) diff --git a/src/internals/doPromap.ts b/src/internals/doPromap.ts new file mode 100644 index 0000000..a687e67 --- /dev/null +++ b/src/internals/doPromap.ts @@ -0,0 +1,13 @@ +import doContramap from "./doContramap"; +import doMap from "./doMap"; +import { Endomorphism } from "fp-ts/lib/function"; +import { flow } from "fp-ts/lib/function"; +import { ComponentType } from "react"; + +// doPromap : ((a -> Props), (Component -> Component)) -> Component -> Component +const doPromap = ( + propsPreprocessor: (props: Outer) => Inner, + higherOrderComponent: Endomorphism> +) => flow(doMap(higherOrderComponent), doContramap(propsPreprocessor)); + +export default doPromap; diff --git a/src/internals/doRotate.js b/src/internals/doRotate.js deleted file mode 100644 index 93bedd1..0000000 --- a/src/internals/doRotate.js +++ /dev/null @@ -1,18 +0,0 @@ -import { compose } from 'recompose' -import doContramap from './doContramap' - -const calculateTransform = oldTransform => rotation => - oldTransform ? `${oldTransform} rotate(${rotation}deg)` : `rotate(${rotation}deg)` - -// doRotate : (Props -> Number) -> Component -> Component -export default getRotateFromProps => Component => - doContramap(props => ({ - ...props, - style: { - ...props.style, - transform: compose( - calculateTransform(props && props.style && props.style.transform), - getRotateFromProps - )(props), - }, - }))(Component) diff --git a/src/internals/doRotate.ts b/src/internals/doRotate.ts new file mode 100644 index 0000000..6c8e9ef --- /dev/null +++ b/src/internals/doRotate.ts @@ -0,0 +1,30 @@ +import { pipe } from "fp-ts/lib/pipeable"; +import doContramap from "./doContramap"; +import { ComponentType } from "react"; + +const calculateTransform = (oldTransform: string | undefined) => ( + rotation: number +): string => + oldTransform + ? `${oldTransform} rotate(${rotation}deg)` + : `rotate(${rotation}deg)`; + +interface EnhancedProps { + style?: { + transform?: string; + }; +} +// doRotate : (Props -> Number) -> Component -> Component +export default

( + getRotateFromProps: (props: P) => number +) => (Component: ComponentType

) => + doContramap(props => ({ + ...props, + style: { + ...props.style, + transform: pipe( + getRotateFromProps(props), + calculateTransform(props?.style?.transform) + ) + } + }))(Component); diff --git a/src/internals/doScale.js b/src/internals/doScale.js deleted file mode 100644 index e7702c6..0000000 --- a/src/internals/doScale.js +++ /dev/null @@ -1,18 +0,0 @@ -import { compose } from 'recompose' -import doContramap from './doContramap' - -const calculateTransform = oldTransform => scaling => - oldTransform ? `${oldTransform} scale(${scaling})` : `scale(${scaling})` - -// doScale : (Props -> Number) -> Component -> Component -export default getScaleFromProps => Component => - doContramap(props => ({ - ...props, - style: { - ...props.style, - transform: compose( - calculateTransform(props && props.style && props.style.transform), - getScaleFromProps - )(props), - }, - }))(Component) diff --git a/src/internals/doScale.ts b/src/internals/doScale.ts new file mode 100644 index 0000000..49bd03b --- /dev/null +++ b/src/internals/doScale.ts @@ -0,0 +1,31 @@ +import { pipe } from "fp-ts/lib/pipeable"; +import doContramap from "./doContramap"; +import { ComponentType } from "react"; + +const calculateTransform = (oldTransform: string | undefined) => ( + scaling: number +): string => + oldTransform ? `${oldTransform} scale(${scaling})` : `scale(${scaling})`; + +interface EnhancedProps { + style?: { + transform?: string; + }; +} + +// doScale : (Props -> Number) -> Component -> Component +const doScale =

( + getScaleFromProps: (props: P) => number +) => (Component: ComponentType

) => + doContramap(props => ({ + ...props, + style: { + ...props.style, + transform: pipe( + getScaleFromProps(props), + calculateTransform(props?.style?.transform) + ) + } + }))(Component); + +export default doScale; diff --git a/src/internals/doTranslate.js b/src/internals/doTranslate.js deleted file mode 100644 index bb9e454..0000000 --- a/src/internals/doTranslate.js +++ /dev/null @@ -1,38 +0,0 @@ -import { compose } from 'recompose' -import doContramap from './doContramap' - -const calculateTransform = oldTransform => ([x, y, z]) => { - switch (true) { - case x != null && y != null && z != null: - return oldTransform - ? `${oldTransform} translate3D(${x}px, ${y}px, ${z}px)` - : `translate3D(${x}px, ${y}px, ${z}px)` - - case x != null && y != null: - return oldTransform - ? `${oldTransform} translate(${x}px, ${y}px)` - : `translate(${x}px, ${y}px)` - - case z != null: - return oldTransform ? `${oldTransform} translateZ(${z}px)` : `translateZ(${z}px)` - - case y != null: - return oldTransform ? `${oldTransform} translateY(${y}px)` : `translateY(${y}px)` - - case x != null: - return oldTransform ? `${oldTransform} translateX(${x}px)` : `translateX(${x}px)` - } -} - -// doTranslate : (Props -> [Number]) -> Component -> Component -export default getTranslateFromProps => Component => - doContramap(props => ({ - ...props, - style: { - ...props.style, - transform: compose( - calculateTransform(props && props.style && props.style.transform), - getTranslateFromProps - )(props), - }, - }))(Component) diff --git a/src/internals/doTranslate.ts b/src/internals/doTranslate.ts new file mode 100644 index 0000000..6db538f --- /dev/null +++ b/src/internals/doTranslate.ts @@ -0,0 +1,52 @@ +import doContramap from "./doContramap"; +import { pipe } from "fp-ts/lib/pipeable"; +import { ComponentType } from "react"; + +const calculateTransform = (oldTransform: string | undefined) => ([ + x, + y, + z +]: Array): string | undefined => { + const old = (str: string): string => + oldTransform ? `${oldTransform} ${str}` : str; + + switch (true) { + case x != null && y != null && z != null: + return old(`translate3D(${x}px, ${y}px, ${z}px)`); + + case x != null && y != null: + return old(`translate(${x}px, ${y}px)`); + + case z != null: + return old(`translateZ(${z}px)`); + + case y != null: + return old(`translateY(${y}px)`); + + case x != null: + return old(`translateX(${x}px)`); + } +}; + +interface EnhancedProps { + style?: { + transform?: string; + }; +} + +// doTranslate : (Props -> [Number]) -> Component -> Component +const doTranslate =

( + getTranslateFromProps: (props: P) => Array +) => (Component: ComponentType

) => + doContramap(props => ({ + ...props, + style: { + ...props.style, + transform: pipe( + getTranslateFromProps(props), + calculateTransform(props?.style?.transform) + ) + } + }))(Component); + +export default doTranslate; diff --git a/src/internals/types.ts b/src/internals/types.ts new file mode 100644 index 0000000..ab7d460 --- /dev/null +++ b/src/internals/types.ts @@ -0,0 +1,10 @@ +import * as React from "react"; + +export type Component = + | keyof JSX.IntrinsicElements + | React.JSXElementConstructor; + +export type PropsOf = JSX.LibraryManagedAttributes< + C, + React.ComponentPropsWithRef +>; diff --git a/src/isReferentiallyTransparentFunctionComponent.js b/src/isReferentiallyTransparentFunctionComponent.js deleted file mode 100644 index b5d3960..0000000 --- a/src/isReferentiallyTransparentFunctionComponent.js +++ /dev/null @@ -1,17 +0,0 @@ -// This is now pointless and should be removed -const isClassComponent = Component => - Boolean( - Component && - Component.prototype && - typeof Component.prototype.render === "function" - ); - -const isReferentiallyTransparentFunctionComponent = Component => - Boolean( - typeof Component === "function" && - !isClassComponent(Component) && - !Component.defaultProps && - !Component.contextTypes - ); - -export default isReferentiallyTransparentFunctionComponent; diff --git a/src/isReferentiallyTransparentFunctionComponent.ts b/src/isReferentiallyTransparentFunctionComponent.ts new file mode 100644 index 0000000..3c76142 --- /dev/null +++ b/src/isReferentiallyTransparentFunctionComponent.ts @@ -0,0 +1,34 @@ +import { + ComponentType, + ComponentClass, + PropsWithChildren, + ReactElement, + WeakValidationMap, + FC +} from "react"; +// This is now pointless and should be removed +const isClassComponent =

( + Component: ComponentType

+): Component is ComponentClass

=> + Boolean( + Component && + Component.prototype && + typeof Component.prototype.render === "function" + ); + +export interface ReferentiallyTransparentFunctionComponent

{ + (props: PropsWithChildren

, context?: any): ReactElement | null; + propTypes?: WeakValidationMap

; +} + +const isReferentiallyTransparentFunctionComponent =

( + Component: ComponentType

+): Component is FC

=> + Boolean( + typeof Component === "function" && + !isClassComponent

(Component) && + !Component.defaultProps && + !Component.contextTypes + ); + +export default isReferentiallyTransparentFunctionComponent; diff --git a/src/partialApplication/addProps.js b/src/partialApplication/addProps.js deleted file mode 100644 index 41f6923..0000000 --- a/src/partialApplication/addProps.js +++ /dev/null @@ -1 +0,0 @@ -export default f => reactDream => reactDream.addProps(f) diff --git a/src/partialApplication/addProps.ts b/src/partialApplication/addProps.ts new file mode 100644 index 0000000..3d2ada5 --- /dev/null +++ b/src/partialApplication/addProps.ts @@ -0,0 +1,5 @@ +import { ReactDream } from "src/ReactDream"; + +export default

(...f: Parameters["addProps"]>) => ( + reactDream: ReactDream

+) => reactDream.addProps(...f); diff --git a/src/partialApplication/ap.js b/src/partialApplication/ap.js deleted file mode 100644 index 1b5d392..0000000 --- a/src/partialApplication/ap.js +++ /dev/null @@ -1 +0,0 @@ -export default f => apply => apply.ap(f) diff --git a/src/partialApplication/ap.ts b/src/partialApplication/ap.ts new file mode 100644 index 0000000..34dc4cd --- /dev/null +++ b/src/partialApplication/ap.ts @@ -0,0 +1,5 @@ +import { ReactDream } from "src/ReactDream"; + +export default

(...f: Parameters["ap"]>) => ( + reactDream: ReactDream

+) => reactDream.ap(...f); diff --git a/src/partialApplication/chain.js b/src/partialApplication/chain.js deleted file mode 100644 index e4ff504..0000000 --- a/src/partialApplication/chain.js +++ /dev/null @@ -1 +0,0 @@ -export default f => chainable => chainable.chain(f) diff --git a/src/partialApplication/chain.ts b/src/partialApplication/chain.ts new file mode 100644 index 0000000..6d97521 --- /dev/null +++ b/src/partialApplication/chain.ts @@ -0,0 +1,5 @@ +import { ReactDream } from "src/ReactDream"; + +export default

(...f: Parameters["chain"]>) => ( + reactDream: ReactDream

+) => reactDream.chain(...f); diff --git a/src/partialApplication/concat.js b/src/partialApplication/concat.js deleted file mode 100644 index 6b4dc18..0000000 --- a/src/partialApplication/concat.js +++ /dev/null @@ -1 +0,0 @@ -export default f => x => x.concat(f) diff --git a/src/partialApplication/concat.ts b/src/partialApplication/concat.ts new file mode 100644 index 0000000..fc1676c --- /dev/null +++ b/src/partialApplication/concat.ts @@ -0,0 +1,5 @@ +import { ReactDream } from "src/ReactDream"; + +export default

(...f: Parameters["concat"]>) => ( + reactDream: ReactDream

+) => reactDream.concat(...f); diff --git a/src/partialApplication/contramap.js b/src/partialApplication/contramap.js deleted file mode 100644 index 33158a8..0000000 --- a/src/partialApplication/contramap.js +++ /dev/null @@ -1 +0,0 @@ -export default f => contravariant => contravariant.contramap(f) diff --git a/src/partialApplication/contramap.ts b/src/partialApplication/contramap.ts new file mode 100644 index 0000000..5ee7c95 --- /dev/null +++ b/src/partialApplication/contramap.ts @@ -0,0 +1,5 @@ +import { ReactDream } from "src/ReactDream"; + +export default (propsPreprocessor: (props: P) => Props) => ( + reactDream: ReactDream

+) => reactDream.contramap(propsPreprocessor); diff --git a/src/partialApplication/debug.js b/src/partialApplication/debug.js deleted file mode 100644 index 57de71a..0000000 --- a/src/partialApplication/debug.js +++ /dev/null @@ -1 +0,0 @@ -export default f => reactDream => reactDream.debug(f) diff --git a/src/partialApplication/debug.ts b/src/partialApplication/debug.ts new file mode 100644 index 0000000..cc99eee --- /dev/null +++ b/src/partialApplication/debug.ts @@ -0,0 +1,5 @@ +import { ReactDream } from "src/ReactDream"; + +export default

(...f: Parameters["debug"]>) => ( + reactDream: ReactDream

+) => reactDream.debug(...f); diff --git a/src/partialApplication/defaultProps.js b/src/partialApplication/defaultProps.js deleted file mode 100644 index a07b7af..0000000 --- a/src/partialApplication/defaultProps.js +++ /dev/null @@ -1 +0,0 @@ -export default f => reactDream => reactDream.defaultProps(f) diff --git a/src/partialApplication/defaultProps.ts b/src/partialApplication/defaultProps.ts new file mode 100644 index 0000000..c5a8e25 --- /dev/null +++ b/src/partialApplication/defaultProps.ts @@ -0,0 +1,5 @@ +import { ReactDream } from "src/ReactDream"; + +export default

(...f: Parameters["defaultProps"]>) => ( + reactDream: ReactDream

+) => reactDream.defaultProps(...f); diff --git a/src/partialApplication/fork.js b/src/partialApplication/fork.js deleted file mode 100644 index d53a0ee..0000000 --- a/src/partialApplication/fork.js +++ /dev/null @@ -1 +0,0 @@ -export default f => reactDream => reactDream.fork(f) diff --git a/src/partialApplication/fork.ts b/src/partialApplication/fork.ts new file mode 100644 index 0000000..2c8ee6f --- /dev/null +++ b/src/partialApplication/fork.ts @@ -0,0 +1,5 @@ +import { ReactDream } from "src/ReactDream"; + +export default

(...f: Parameters["fork"]>) => ( + reactDream: ReactDream

+) => reactDream.fork(...f); diff --git a/src/partialApplication/log.js b/src/partialApplication/log.js deleted file mode 100644 index c26ed59..0000000 --- a/src/partialApplication/log.js +++ /dev/null @@ -1 +0,0 @@ -export default f => reactDream => reactDream.log(f) diff --git a/src/partialApplication/log.ts b/src/partialApplication/log.ts new file mode 100644 index 0000000..fbeb0b0 --- /dev/null +++ b/src/partialApplication/log.ts @@ -0,0 +1,5 @@ +import { ReactDream } from "src/ReactDream"; + +export default

(...f: Parameters["log"]>) => ( + reactDream: ReactDream

+) => reactDream.log(...f); diff --git a/src/partialApplication/map.js b/src/partialApplication/map.js deleted file mode 100644 index 5cbd7cf..0000000 --- a/src/partialApplication/map.js +++ /dev/null @@ -1 +0,0 @@ -export default f => functor => functor.map(f) diff --git a/src/partialApplication/map.ts b/src/partialApplication/map.ts new file mode 100644 index 0000000..d829c27 --- /dev/null +++ b/src/partialApplication/map.ts @@ -0,0 +1,5 @@ +import { ReactDream } from "src/ReactDream"; + +export default

(...f: Parameters["map"]>) => ( + reactDream: ReactDream

+) => reactDream.map(...f); diff --git a/src/partialApplication/name.js b/src/partialApplication/name.js deleted file mode 100644 index 838cf51..0000000 --- a/src/partialApplication/name.js +++ /dev/null @@ -1 +0,0 @@ -export default f => reactDream => reactDream.name(f) diff --git a/src/partialApplication/name.ts b/src/partialApplication/name.ts new file mode 100644 index 0000000..94ab7f3 --- /dev/null +++ b/src/partialApplication/name.ts @@ -0,0 +1,5 @@ +import { ReactDream } from "src/ReactDream"; + +export default

(...f: Parameters["name"]>) => ( + reactDream: ReactDream

+) => reactDream.name(...f); diff --git a/src/partialApplication/promap.js b/src/partialApplication/promap.js deleted file mode 100644 index 065330f..0000000 --- a/src/partialApplication/promap.js +++ /dev/null @@ -1 +0,0 @@ -export default f => profunctor => profunctor.promap(f) diff --git a/src/partialApplication/promap.ts b/src/partialApplication/promap.ts new file mode 100644 index 0000000..b072670 --- /dev/null +++ b/src/partialApplication/promap.ts @@ -0,0 +1,5 @@ +import { ReactDream } from "src/ReactDream"; + +export default

(...f: Parameters["promap"]>) => ( + reactDream: ReactDream

+) => reactDream.promap(...f); diff --git a/src/partialApplication/propTypes.js b/src/partialApplication/propTypes.js deleted file mode 100644 index 60a65cb..0000000 --- a/src/partialApplication/propTypes.js +++ /dev/null @@ -1 +0,0 @@ -export default f => x => x.propTypes(f) diff --git a/src/partialApplication/propTypes.ts b/src/partialApplication/propTypes.ts new file mode 100644 index 0000000..80e22b0 --- /dev/null +++ b/src/partialApplication/propTypes.ts @@ -0,0 +1,5 @@ +import { ReactDream } from "src/ReactDream"; + +export default

(...f: Parameters["propTypes"]>) => ( + reactDream: ReactDream

+) => reactDream.propTypes(...f); diff --git a/src/partialApplication/removeProps.js b/src/partialApplication/removeProps.js deleted file mode 100644 index ddf46a5..0000000 --- a/src/partialApplication/removeProps.js +++ /dev/null @@ -1 +0,0 @@ -export default f => reactDream => reactDream.removeProps(f) diff --git a/src/partialApplication/removeProps.ts b/src/partialApplication/removeProps.ts new file mode 100644 index 0000000..5113c81 --- /dev/null +++ b/src/partialApplication/removeProps.ts @@ -0,0 +1,5 @@ +import { ReactDream } from "src/ReactDream"; + +export default

(...f: Parameters["removeProps"]>) => ( + reactDream: ReactDream

+) => reactDream.removeProps(...f); diff --git a/src/partialApplication/rotate.js b/src/partialApplication/rotate.js deleted file mode 100644 index bca97f4..0000000 --- a/src/partialApplication/rotate.js +++ /dev/null @@ -1 +0,0 @@ -export default f => reactDream => reactDream.rotate(f) diff --git a/src/partialApplication/rotate.ts b/src/partialApplication/rotate.ts new file mode 100644 index 0000000..db77522 --- /dev/null +++ b/src/partialApplication/rotate.ts @@ -0,0 +1,5 @@ +import { ReactDream } from "src/ReactDream"; + +export default

(...f: Parameters["rotate"]>) => ( + reactDream: ReactDream

+) => reactDream.rotate(...f); diff --git a/src/partialApplication/scale.js b/src/partialApplication/scale.js deleted file mode 100644 index 3287aeb..0000000 --- a/src/partialApplication/scale.js +++ /dev/null @@ -1 +0,0 @@ -export default f => reactDream => reactDream.scale(f) diff --git a/src/partialApplication/scale.ts b/src/partialApplication/scale.ts new file mode 100644 index 0000000..54e35fe --- /dev/null +++ b/src/partialApplication/scale.ts @@ -0,0 +1,5 @@ +import { ReactDream } from "src/ReactDream"; + +export default

(...f: Parameters["scale"]>) => ( + reactDream: ReactDream

+) => reactDream.scale(...f); diff --git a/src/partialApplication/style.js b/src/partialApplication/style.js deleted file mode 100644 index 643b466..0000000 --- a/src/partialApplication/style.js +++ /dev/null @@ -1 +0,0 @@ -export default f => reactDream => reactDream.style(f) diff --git a/src/partialApplication/style.ts b/src/partialApplication/style.ts new file mode 100644 index 0000000..77a7eec --- /dev/null +++ b/src/partialApplication/style.ts @@ -0,0 +1,5 @@ +import { ReactDream } from "src/ReactDream"; + +export default

(...f: Parameters["style"]>) => ( + reactDream: ReactDream

+) => reactDream.style(...f); diff --git a/src/partialApplication/translate.js b/src/partialApplication/translate.js deleted file mode 100644 index f0297da..0000000 --- a/src/partialApplication/translate.js +++ /dev/null @@ -1 +0,0 @@ -export default f => reactDream => reactDream.translate(f) diff --git a/src/partialApplication/translate.ts b/src/partialApplication/translate.ts new file mode 100644 index 0000000..5f28ae6 --- /dev/null +++ b/src/partialApplication/translate.ts @@ -0,0 +1,5 @@ +import { ReactDream } from "src/ReactDream"; + +export default

(...f: Parameters["translate"]>) => ( + reactDream: ReactDream

+) => reactDream.translate(...f); diff --git a/src/styleFromProps.js b/src/styleFromProps.js deleted file mode 100644 index 4985500..0000000 --- a/src/styleFromProps.js +++ /dev/null @@ -1,8 +0,0 @@ -// styleFromProps : (Props -> Style) -> (Props -> Props) -export default getStyleFromProps => props => ({ - ...props, - style: { - ...getStyleFromProps(props), - ...(props.style || {}), - }, -}) diff --git a/src/styleFromProps.ts b/src/styleFromProps.ts new file mode 100644 index 0000000..6a418b3 --- /dev/null +++ b/src/styleFromProps.ts @@ -0,0 +1,17 @@ +import { CSSProperties } from "react"; + +// styleFromProps : (Props -> Style) -> (Props -> Props) + +interface Props { + style?: CSSProperties; +} + +export default

( + getStyleFromProps: (props: P) => CSSProperties +) => (props: P) => ({ + ...props, + style: { + ...getStyleFromProps(props), + ...(props.style ?? {}) + } +}); diff --git a/src/types.ts b/src/types.ts new file mode 100644 index 0000000..d0269d6 --- /dev/null +++ b/src/types.ts @@ -0,0 +1,4 @@ +import { ComponentType } from "react"; +import { Endomorphism } from "fp-ts/lib/function"; + +export type Hoc

= Endomorphism>; diff --git a/src/withStyleFromProps.js b/src/withStyleFromProps.js deleted file mode 100644 index fd6882e..0000000 --- a/src/withStyleFromProps.js +++ /dev/null @@ -1,4 +0,0 @@ -import doContramap from './internals/doContramap' -import styleFromProps from './styleFromProps' - -export default getStyleFromProps => doContramap(styleFromProps(getStyleFromProps)) diff --git a/src/withStyleFromProps.ts b/src/withStyleFromProps.ts new file mode 100644 index 0000000..9f3a186 --- /dev/null +++ b/src/withStyleFromProps.ts @@ -0,0 +1,6 @@ +import doContramap from "./internals/doContramap"; +import styleFromProps from "./styleFromProps"; +import { CSSProperties } from "react"; + +export default

(getStyleFromProps: (props: P) => CSSProperties) => + doContramap(styleFromProps(getStyleFromProps)); diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..2e25615 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,36 @@ +{ + "compilerOptions": { + "allowJs": true, + "allowSyntheticDefaultImports": true, + "baseUrl": ".", + "checkJs": true, + "esModuleInterop": true, + "declaration": true, + "forceConsistentCasingInFileNames": true, + "isolatedModules": true, + "outDir": "./dist", + "jsx": "preserve", + "lib": ["dom", "es2015", "es2017"], + "module": "esnext", + "moduleResolution": "node", + "noImplicitAny": true, + "paths": { + "src/*": ["src/*"], + "@hocs/with-debugger": ["src/@types/@hocs__with-debugger"], + "@hocs/with-log": ["src/@types/@hocs__with-log"] + }, + "noUnusedLocals": true, + "noUnusedParameters": true, + "preserveConstEnums": true, + "removeComments": true, + "resolveJsonModule": true, + "skipLibCheck": true, + "sourceMap": true, + "strict": true, + "strictNullChecks": true, + "target": "esnext", + "typeRoots": ["./src/@types", "./node_modules/@types"] + }, + "include": ["./src/**/*"], + "exclude": ["node_modules"] +} diff --git a/yarn.lock b/yarn.lock index 11533c9..effe3d0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11,8 +11,9 @@ resolved "https://registry.yarnpkg.com/@hocs/with-log/-/with-log-0.1.0.tgz#52d171cdcad863462ee6545c84f4fd97741abc50" "@klarna/higher-order-components@^3.0.1": - version "3.0.1" - resolved "https://registry.yarnpkg.com/@klarna/higher-order-components/-/higher-order-components-3.0.1.tgz#d1f71733af58587fadbf065ba233237b720baf83" + version "3.1.0" + resolved "https://registry.yarnpkg.com/@klarna/higher-order-components/-/higher-order-components-3.1.0.tgz#1e1b3b7c1fd859024882bc4de2ceca4e5654a454" + integrity sha1-Hhs7fB/YWQJIgrxN4s7KTlZUpFQ= dependencies: collect-fps "2.0.0" deepmerge "^1.4.4" @@ -20,6 +21,26 @@ recompose "^0.23.4" seed-random "^2.2.0" +"@types/prop-types@*": + version "15.7.3" + resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.3.tgz#2ab0d5da2e5815f94b0b9d4b95d1e5f243ab2ca7" + integrity sha512-KfRL3PuHmqQLOG+2tGpRO26Ctg+Cq1E01D2DMriKEATHgWLfeNDmq9e29Q9WIky0dQ3NPkd1mzYH8Lm936Z9qw== + +"@types/react@*", "@types/react@^16.9.17": + version "16.9.17" + resolved "https://registry.yarnpkg.com/@types/react/-/react-16.9.17.tgz#58f0cc0e9ec2425d1441dd7b623421a867aa253e" + integrity sha512-UP27In4fp4sWF5JgyV6pwVPAQM83Fj76JOcg02X5BZcpSu5Wx+fP9RMqc2v0ssBoQIFvD5JdKY41gjJJKmw6Bg== + dependencies: + "@types/prop-types" "*" + csstype "^2.2.0" + +"@types/recompose@^0.30.7": + version "0.30.7" + resolved "https://registry.yarnpkg.com/@types/recompose/-/recompose-0.30.7.tgz#0d47f3da3bdf889a4f36d4ca7531fac1eee1c6bd" + integrity sha512-kEvD7XMguXgG7jJJS//cE1QTbkFj2qDtIPAg1FvXxE8D6jD1C0WabJjT7cVitC7TK0N5I3yp2955hqNFFZV0wg== + dependencies: + "@types/react" "*" + abab@^1.0.4: version "1.0.4" resolved "https://registry.yarnpkg.com/abab/-/abab-1.0.4.tgz#5faad9c2c07f60dd76770f71cf025b62a63cfd4e" @@ -54,10 +75,12 @@ ajv@^5.1.0: ansi-regex@^2.0.0: version "2.1.1" resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-2.1.1.tgz#c3b33ab5ee360d86e0e628f0468ae7ef27d654df" + integrity sha1-w7M6te42DYbg5ijwRorn7yfWVN8= ansi-styles@^2.2.1: version "2.2.1" resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-2.2.1.tgz#b432dd3358b634cf75e1e4664368240533c1ddbe" + integrity sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4= anymatch@^1.3.0: version "1.3.2" @@ -98,6 +121,7 @@ array-unique@^0.2.1: asap@~2.0.3: version "2.0.6" resolved "https://registry.yarnpkg.com/asap/-/asap-2.0.6.tgz#e50347611d7e690943208bbdafebcbc2fb866d46" + integrity sha1-5QNHYR1+aQlDIIu9r+vLwvuGbUY= asn1@~0.2.3: version "0.2.4" @@ -813,6 +837,7 @@ chalk@^1.1.0, chalk@^1.1.3: change-emitter@^0.1.2: version "0.1.6" resolved "https://registry.yarnpkg.com/change-emitter/-/change-emitter-0.1.6.tgz#e8b2fe3d7f1ab7d69a32199aff91ea6931409515" + integrity sha1-6LL+PX8at9aaMhma/5HqaTFAlRU= chokidar@^1.6.1: version "1.7.0" @@ -844,6 +869,7 @@ code-point-at@^1.0.0: collect-fps@2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/collect-fps/-/collect-fps-2.0.0.tgz#62adee44763dbebe681c4cba8757265d6f26916e" + integrity sha1-Yq3uRHY9vr5oHEy6h1cmXW8mkW4= combined-stream@1.0.6: version "1.0.6" @@ -876,6 +902,7 @@ convert-source-map@^1.5.0, convert-source-map@^1.5.1: core-js@^1.0.0: version "1.2.7" resolved "https://registry.yarnpkg.com/core-js/-/core-js-1.2.7.tgz#652294c14651db28fa93bd2d5ff2983a4f08c636" + integrity sha1-ZSKUwUZR2yj6k70tX/KYOk8IxjY= core-js@^2.4.0: version "2.4.1" @@ -899,6 +926,11 @@ cssstyle@^1.0.0: dependencies: cssom "0.3.x" +csstype@^2.2.0: + version "2.6.8" + resolved "https://registry.yarnpkg.com/csstype/-/csstype-2.6.8.tgz#0fb6fc2417ffd2816a418c9336da74d7f07db431" + integrity sha512-msVS9qTuMT5zwAGCVm4mxfrZ18BNc6Csd0oJAtiFMZ1FAx1CCvy2+5MDmYoix63LM/6NDbNtodCiGYGmFgO0dA== + dashdash@^1.12.0: version "1.14.1" resolved "https://registry.yarnpkg.com/dashdash/-/dashdash-1.14.1.tgz#853cfa0f7cbe2fed5de20326b8dd581035f6e2f0" @@ -934,8 +966,9 @@ deep-is@~0.1.3: resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34" deepmerge@^1.4.4: - version "1.5.0" - resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-1.5.0.tgz#00bc5b88fd23b8130f9f5049071c3420e07a5465" + version "1.5.2" + resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-1.5.2.tgz#10499d868844cdad4fee0842df8c7f6f0c95a753" + integrity sha512-95k0GDqvBjZavkuvzx/YqVLv/6YYa17fz6ILMSf7neqQITCPbnfEnQvEgMPNjH4kgobe7+WIL0yJEHku+H3qtQ== delayed-stream@~1.0.0: version "1.0.0" @@ -971,12 +1004,14 @@ ecc-jsbn@~0.1.1: encoding@^0.1.11: version "0.1.12" resolved "https://registry.yarnpkg.com/encoding/-/encoding-0.1.12.tgz#538b66f3ee62cd1ab51ec323829d1f9480c74beb" + integrity sha1-U4tm8+5izRq1HsMjgp0flIDHS+s= dependencies: iconv-lite "~0.4.13" escape-string-regexp@^1.0.2: version "1.0.5" resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" + integrity sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ= escodegen@^1.9.1: version "1.11.0" @@ -1040,20 +1075,9 @@ fast-levenshtein@~2.0.4: resolved "https://registry.yarnpkg.com/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz#3d8a5c66883a16a30ca8643e851f19baa7797917" fbjs@^0.8.1: - version "0.8.14" - resolved "https://registry.yarnpkg.com/fbjs/-/fbjs-0.8.14.tgz#d1dbe2be254c35a91e09f31f9cd50a40b2a0ed1c" - dependencies: - core-js "^1.0.0" - isomorphic-fetch "^2.1.1" - loose-envify "^1.0.0" - object-assign "^4.1.0" - promise "^7.1.1" - setimmediate "^1.0.5" - ua-parser-js "^0.7.9" - -fbjs@^0.8.16: version "0.8.17" resolved "https://registry.yarnpkg.com/fbjs/-/fbjs-0.8.17.tgz#c4d598ead6949112653d6588b01a5cdcd9f90fdd" + integrity sha1-xNWY6taUkRJlPWWIsBpc3Nn5D90= dependencies: core-js "^1.0.0" isomorphic-fetch "^2.1.1" @@ -1078,8 +1102,9 @@ fill-range@^2.1.0: repeat-string "^1.5.2" folktale@^v2.0.0-rc1: - version "2.1.0" - resolved "https://registry.yarnpkg.com/folktale/-/folktale-2.1.0.tgz#3332b9e37b4b92150788b72bd0e2ddd8d70e4096" + version "2.3.2" + resolved "https://registry.yarnpkg.com/folktale/-/folktale-2.3.2.tgz#38231b039e5ef36989920cbf805bf6b227bf4fd4" + integrity sha512-+8GbtQBwEqutP0v3uajDDoN64K2ehmHd0cjlghhxh0WpcfPzAIjPA03e1VvHlxL02FVGR0A6lwXsNQKn3H1RNQ== for-in@^1.0.1: version "1.0.2" @@ -1103,6 +1128,11 @@ form-data@~2.3.1: combined-stream "1.0.6" mime-types "^2.1.12" +fp-ts@^2.4.1: + version "2.4.1" + resolved "https://registry.yarnpkg.com/fp-ts/-/fp-ts-2.4.1.tgz#d20c785ff8179930922c7477c31f1ca44f763ae9" + integrity sha512-dPal5+rPN7k4ciZ2+O0+i75bbp17uTUoRkWWqJpkKed7wVcA5y/2jH4ZhunzUrJPuaG+mN9ZNf0pv5P7u/k7JQ== + fs-minipass@^1.2.5: version "1.2.5" resolved "https://registry.yarnpkg.com/fs-minipass/-/fs-minipass-1.2.5.tgz#06c277218454ec288df77ada54a03b8702aacb9d" @@ -1189,6 +1219,7 @@ har-validator@~5.0.3: has-ansi@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/has-ansi/-/has-ansi-2.0.0.tgz#34f5049ce1ecdf2b0649af3ef24e45ed35416d91" + integrity sha1-NPUEnOHs3ysGSa8+8k5F7TVBbZE= dependencies: ansi-regex "^2.0.0" @@ -1199,6 +1230,7 @@ has-unicode@^2.0.0: hoist-non-react-statics@^1.0.0: version "1.2.0" resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-1.2.0.tgz#aa448cf0986d55cc40773b17174b7dd066cb7cfb" + integrity sha1-qkSM8JhtVcxAdzsXF0t90GbLfPs= home-or-tmp@^2.0.0: version "2.0.0" @@ -1236,8 +1268,11 @@ iconv-lite@^0.4.4: safer-buffer ">= 2.1.2 < 3" iconv-lite@~0.4.13: - version "0.4.18" - resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.18.tgz#23d8656b16aae6742ac29732ea8f0336a4789cf2" + version "0.4.24" + resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b" + integrity sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA== + dependencies: + safer-buffer ">= 2.1.2 < 3" ignore-walk@^3.0.1: version "3.0.1" @@ -1248,14 +1283,17 @@ ignore-walk@^3.0.1: immutable-ext@^1.0.8: version "1.1.5" resolved "https://registry.yarnpkg.com/immutable-ext/-/immutable-ext-1.1.5.tgz#3cdf27a067527c85817bf161a0dad1361ed579cb" + integrity sha1-PN8noGdSfIWBe/FhoNrRNh7Vecs= immutable@^3.8.1: version "3.8.2" resolved "https://registry.yarnpkg.com/immutable/-/immutable-3.8.2.tgz#c2439951455bb39913daf281376f1530e104adf3" + integrity sha1-wkOZUUVbs5kT2vKBN28VMOEErfM= infestines@^0.4.2: - version "0.4.9" - resolved "https://registry.yarnpkg.com/infestines/-/infestines-0.4.9.tgz#51480ddce36430b102835153bddac61a15c4bbde" + version "0.4.11" + resolved "https://registry.yarnpkg.com/infestines/-/infestines-0.4.11.tgz#1d0d164ff1831ffcbafbd02f53bc60140dd52197" + integrity sha512-09nHagZLOYUaXKHqdV+nxEaYaD0hRlKyhQMhgTMwfbvWpMkowXf4XLZzAkLq6Y90wZ7Wqm6aMoL2trBsNNKGeg== inflight@^1.0.4: version "1.0.6" @@ -1353,6 +1391,7 @@ is-primitive@^2.0.0: is-stream@^1.0.1: version "1.1.0" resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44" + integrity sha1-EtSj3U5o4Lec6428hBc66A2RykQ= is-typedarray@~1.0.0: version "1.0.0" @@ -1371,6 +1410,7 @@ isobject@^2.0.0: isomorphic-fetch@^2.1.1: version "2.2.1" resolved "https://registry.yarnpkg.com/isomorphic-fetch/-/isomorphic-fetch-2.2.1.tgz#611ae1acf14f5e81f729507472819fe9733558a9" + integrity sha1-YRrhrPFPXoH3KVB0coGf6XM1WKk= dependencies: node-fetch "^1.0.1" whatwg-fetch ">=0.10.0" @@ -1383,6 +1423,11 @@ js-tokens@^3.0.0, js-tokens@^3.0.2: version "3.0.2" resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b" +"js-tokens@^3.0.0 || ^4.0.0": + version "4.0.0" + resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499" + integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ== + jsbn@~0.1.0: version "0.1.1" resolved "https://registry.yarnpkg.com/jsbn/-/jsbn-0.1.1.tgz#a5e654c2e5a2deb5f201d96cefbca80c0ef2f513" @@ -1458,6 +1503,7 @@ jsprim@^1.2.2: jwt-decode@^2.2.0: version "2.2.0" resolved "https://registry.yarnpkg.com/jwt-decode/-/jwt-decode-2.2.0.tgz#7d86bd56679f58ce6a84704a657dd392bba81a79" + integrity sha1-fYa9VmefWM5qhHBKZX3TkruoGnk= kind-of@^3.0.2: version "3.2.2" @@ -1490,11 +1536,12 @@ lodash@^4.13.1, lodash@^4.17.4, lodash@^4.2.0: version "4.17.15" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548" -loose-envify@^1.0.0, loose-envify@^1.1.0, loose-envify@^1.3.1: - version "1.3.1" - resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.3.1.tgz#d1a8ad33fa9ce0e713d65fdd0ac8b748d478c848" +loose-envify@^1.0.0, loose-envify@^1.1.0, loose-envify@^1.4.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf" + integrity sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q== dependencies: - js-tokens "^3.0.0" + js-tokens "^3.0.0 || ^4.0.0" micromatch@^2.1.5: version "2.3.11" @@ -1584,8 +1631,9 @@ needle@^2.2.0: sax "^1.2.4" node-fetch@^1.0.1: - version "1.7.1" - resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-1.7.1.tgz#899cb3d0a3c92f952c47f1b876f4c8aeabd400d5" + version "1.7.3" + resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-1.7.3.tgz#980f6f72d85211a5347c6b2bc18c5b84c3eb47ef" + integrity sha512-NhZ4CsKx7cYm2vSrBAr2PvFOe6sWDf0UYLRqA6svUYg7+/TSfVAu49jYC4BvQ4Sms9SZgdqGBgroqfDhJdTyKQ== dependencies: encoding "^0.1.11" is-stream "^1.0.1" @@ -1653,6 +1701,7 @@ oauth-sign@~0.8.2: object-assign@^4.1.0, object-assign@^4.1.1: version "4.1.1" resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863" + integrity sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM= object.omit@^2.0.0: version "2.0.1" @@ -1717,6 +1766,7 @@ parse5@4.0.0: partial.lenses@^9.4.1: version "9.8.0" resolved "https://registry.yarnpkg.com/partial.lenses/-/partial.lenses-9.8.0.tgz#f8514fccc9eeb539b4dfcdb66249ed18d1f84202" + integrity sha1-+FFPzMnutTm03822YkntGNH4QgI= dependencies: infestines "^0.4.2" @@ -1740,9 +1790,10 @@ preserve@^0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b" -prettier@^1.5.3: - version "1.5.3" - resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.5.3.tgz#59dadc683345ec6b88f88b94ed4ae7e1da394bfe" +prettier@^1.19.1: + version "1.19.1" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.19.1.tgz#f7d7f5ff8a9cd872a7be4ca142095956a60797cb" + integrity sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew== private@^0.1.6: version "0.1.7" @@ -1759,15 +1810,18 @@ process-nextick-args@~1.0.6: promise@^7.1.1: version "7.3.1" resolved "https://registry.yarnpkg.com/promise/-/promise-7.3.1.tgz#064b72602b18f90f29192b8b1bc418ffd1ebd3bf" + integrity sha512-nolQXZ/4L+bP/UGlkfaIujX9BKxGwmQ9OT4mOt5yvy8iK1h3wqTEJCijzGANTCCl9nWjY41juyAn2K3Q1hLLTg== dependencies: asap "~2.0.3" -prop-types@^15.6.0: - version "15.6.2" - resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.6.2.tgz#05d5ca77b4453e985d60fc7ff8c859094a497102" +prop-types@^15.6.2: + version "15.7.2" + resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.7.2.tgz#52c41e75b8c87e72b9d9360e0206b99dcbffa6c5" + integrity sha512-8QQikdH7//R2vurIJSutZ1smHYTcLpRWEOlHnzcWHmBYrOGUysKwSsrC89BCiFj3CbrfJ/nXFdJepOVrY1GCHQ== dependencies: - loose-envify "^1.3.1" + loose-envify "^1.4.0" object-assign "^4.1.1" + react-is "^16.8.1" psl@^1.1.24: version "1.1.28" @@ -1805,27 +1859,29 @@ rc@^1.1.7: minimist "^1.2.0" strip-json-comments "~2.0.1" -react-is@^16.4.1: - version "16.4.1" - resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.4.1.tgz#d624c4650d2c65dbd52c72622bbf389435d9776e" +react-is@^16.8.1, react-is@^16.8.6: + version "16.12.0" + resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.12.0.tgz#2cc0fe0fba742d97fd527c42a13bec4eeb06241c" + integrity sha512-rPCkf/mWBtKc97aLL9/txD8DZdemK0vkA3JMLShjlJB3Pj3s+lpf1KaBzMfQrAmhMQB0n1cU/SUGgKKBCe837Q== react-test-renderer@^16.0.0: - version "16.4.1" - resolved "https://registry.yarnpkg.com/react-test-renderer/-/react-test-renderer-16.4.1.tgz#f2fb30c2c7b517db6e5b10ed20bb6b0a7ccd8d70" + version "16.12.0" + resolved "https://registry.yarnpkg.com/react-test-renderer/-/react-test-renderer-16.12.0.tgz#11417ffda579306d4e841a794d32140f3da1b43f" + integrity sha512-Vj/teSqt2oayaWxkbhQ6gKis+t5JrknXfPVo+aIJ8QwYAqMPH77uptOdrlphyxl8eQI/rtkOYg86i/UWkpFu0w== dependencies: - fbjs "^0.8.16" object-assign "^4.1.1" - prop-types "^15.6.0" - react-is "^16.4.1" + prop-types "^15.6.2" + react-is "^16.8.6" + scheduler "^0.18.0" react@^16.0.0: - version "16.4.1" - resolved "https://registry.yarnpkg.com/react/-/react-16.4.1.tgz#de51ba5764b5dbcd1f9079037b862bd26b82fe32" + version "16.12.0" + resolved "https://registry.yarnpkg.com/react/-/react-16.12.0.tgz#0c0a9c6a142429e3614834d5a778e18aa78a0b83" + integrity sha512-fglqy3k5E+81pA8s+7K0/T3DBCF0ZDOher1elBFzF7O6arXJgzyu/FW+COxFvAWXJoJN9KIZbT2LXlukwphYTA== dependencies: - fbjs "^0.8.16" loose-envify "^1.1.0" object-assign "^4.1.1" - prop-types "^15.6.0" + prop-types "^15.6.2" readable-stream@^2.0.2, readable-stream@^2.0.6: version "2.3.3" @@ -1851,6 +1907,7 @@ readdirp@^2.0.0: recompose@^0.23.4: version "0.23.5" resolved "https://registry.yarnpkg.com/recompose/-/recompose-0.23.5.tgz#72ac8261246bec378235d187467d02a721e8b1de" + integrity sha1-cqyCYSRr7DeCNdGHRn0CpyHosd4= dependencies: change-emitter "^0.1.2" fbjs "^0.8.1" @@ -1990,9 +2047,18 @@ sax@^1.2.4: version "1.2.4" resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9" +scheduler@^0.18.0: + version "0.18.0" + resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.18.0.tgz#5901ad6659bc1d8f3fdaf36eb7a67b0d6746b1c4" + integrity sha512-agTSHR1Nbfi6ulI0kYNK0203joW2Y5W4po4l+v03tOoiJKpTBbxpNhWDvqc/4IcOw+KLmSiQLTasZ4cab2/UWQ== + dependencies: + loose-envify "^1.1.0" + object-assign "^4.1.1" + seed-random@^2.2.0: version "2.2.0" resolved "https://registry.yarnpkg.com/seed-random/-/seed-random-2.2.0.tgz#2a9b19e250a817099231a5b99a4daf80b7fbed54" + integrity sha1-KpsZ4lCoFwmSMaW5mk2vgLf77VQ= semver@^5.3.0: version "5.4.1" @@ -2009,6 +2075,7 @@ set-immediate-shim@^1.0.1: setimmediate@^1.0.5: version "1.0.5" resolved "https://registry.yarnpkg.com/setimmediate/-/setimmediate-1.0.5.tgz#290cbb232e306942d7d7ea9b83732ab7856f8285" + integrity sha1-KQy7Iy4waULX1+qbg3Mqt4VvgoU= signal-exit@^3.0.0: version "3.0.2" @@ -2081,10 +2148,12 @@ strip-json-comments@~2.0.1: supports-color@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-2.0.0.tgz#535d045ce6b6363fa40117084629995e9df324c7" + integrity sha1-U10EXOa2Nj+kARcIRimZXp3zJMc= symbol-observable@^1.0.4: - version "1.0.4" - resolved "https://registry.yarnpkg.com/symbol-observable/-/symbol-observable-1.0.4.tgz#29bf615d4aa7121bdd898b22d4b3f9bc4e2aa03d" + version "1.2.0" + resolved "https://registry.yarnpkg.com/symbol-observable/-/symbol-observable-1.2.0.tgz#c22688aed4eab3cdc2dfeacbb561660560a00804" + integrity sha512-e900nM8RRtGhlV36KGEU9k65K3mPb1WV70OdjfxlG2EAuM1noi/E/BaW/uMhL7bPEssK8QV57vN3esixjUvcXQ== symbol-tree@^3.2.2: version "3.2.2" @@ -2145,13 +2214,15 @@ type-check@~0.3.2: dependencies: prelude-ls "~1.1.2" -ua-parser-js@^0.7.18: - version "0.7.18" - resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.18.tgz#a7bfd92f56edfb117083b69e31d2aa8882d4b1ed" +typescript@^3.7.5: + version "3.7.5" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.7.5.tgz#0692e21f65fd4108b9330238aac11dd2e177a1ae" + integrity sha512-/P5lkRXkWHNAbcJIiHPfRoKqyd7bsyCma1hZNUGfn20qm64T6ZBlrzprymeu918H+mB/0rIg2gGK/BXkhhYgBw== -ua-parser-js@^0.7.9: - version "0.7.14" - resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.14.tgz#110d53fa4c3f326c121292bbeac904d2e03387ca" +ua-parser-js@^0.7.18: + version "0.7.21" + resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.21.tgz#853cf9ce93f642f67174273cc34565ae6f308777" + integrity sha512-+O8/qh/Qj8CgC6eYBVBykMrNtp5Gebn4dlGD/kKXVkJNDwyrAwSIqwz8CDf+tsAIWVycKcku6gIXJ0qwx/ZXaQ== user-home@^1.1.1: version "1.1.1" @@ -2185,29 +2256,38 @@ w3c-hr-time@^1.0.1: dependencies: browser-process-hrtime "^0.1.2" -washington.core@^2.0.0-rc.3: - version "2.0.0-rc.3" - resolved "https://registry.yarnpkg.com/washington.core/-/washington.core-2.0.0-rc.3.tgz#e9b52f736f177961fa962160f9810d4068c2db01" +washington.core@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/washington.core/-/washington.core-2.0.0.tgz#68bb219c8870a2f753627aece1aac66a2451465f" + integrity sha512-8/D33dkYBsp3dGmjdCiH4R+111X7jX2RbyCuSG57P9YuVgKFDts7sATzx3ZUQwGJlggfIOWtPClKwpzJrDbrpQ== dependencies: folktale "^v2.0.0-rc1" immutable "^3.8.1" immutable-ext "^1.0.8" partial.lenses "^9.4.1" -washington.formatter.terminal@^2.0.0-rc.3: - version "2.0.0-rc.3" - resolved "https://registry.yarnpkg.com/washington.formatter.terminal/-/washington.formatter.terminal-2.0.0-rc.3.tgz#da80f5a8faa4d56a6d7297783e55d657c41e7417" +washington.dsl@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/washington.dsl/-/washington.dsl-2.0.0.tgz#01ae7aa87d13366270c1cd1ef432439e980d3d3a" + integrity sha512-Y+0uuqAlknVc+1SvLKnwTaEJSTUUe4kxqZ3C4QIqC70kM5UCmU0xz4wL48ygk5nKgvZ0gd3tzkpPhgv+b0TeuA== + +washington.formatter.terminal@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/washington.formatter.terminal/-/washington.formatter.terminal-2.0.0.tgz#d05711d888cf43c0f31e8d09ee899f0c5672c076" + integrity sha512-MtZZnNlwDW7liKyBf74sJQTKQzjyezHlouIy+c98qTfiZ4rn1cAmVx8+Lt4fyLPnDDavyjskCCzJxfSiEmeECg== dependencies: chalk "^1.1.3" folktale "^v2.0.0-rc1" partial.lenses "^9.4.1" washington@^2.0.0-rc.3: - version "2.0.0-rc.3" - resolved "https://registry.yarnpkg.com/washington/-/washington-2.0.0-rc.3.tgz#40d40ef0dde10563f9f469e8ed38a25feae1baf7" + version "2.0.0" + resolved "https://registry.yarnpkg.com/washington/-/washington-2.0.0.tgz#afa9cbd7da270027787beb219d5972285256c833" + integrity sha512-d7zCIXzmdWqWurQNGBbgUIwOO/x1wd4dMmGNWY/nxxeBN3R07A+uJ3RFOudZu2IuHw0Ao4Sp++fn5B2SXJ4zZA== dependencies: - washington.core "^2.0.0-rc.3" - washington.formatter.terminal "^2.0.0-rc.3" + washington.core "^2.0.0" + washington.dsl "^2.0.0" + washington.formatter.terminal "^2.0.0" webidl-conversions@^4.0.2: version "4.0.2" @@ -2226,8 +2306,9 @@ whatwg-encoding@^1.0.3: iconv-lite "0.4.19" whatwg-fetch@>=0.10.0: - version "2.0.3" - resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-2.0.3.tgz#9c84ec2dcf68187ff00bc64e1274b442176e1c84" + version "3.0.0" + resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-3.0.0.tgz#fc804e458cc460009b1a2b966bc8817d2578aefb" + integrity sha512-9GSJUgz1D4MfyKU7KRqwOjXCXTqWdFNvEr7eUBYchQiVc744mqK/MzXPNR2WsPkmkOa4ywfg8C2n8h+13Bey1Q== whatwg-mimetype@^2.0.0, whatwg-mimetype@^2.1.0: version "2.1.0" From d9bdb855245a2dc36f7e223c43dd57e51db3d1ed Mon Sep 17 00:00:00 2001 From: brettm12345 Date: Sun, 19 Jan 2020 09:05:33 -0500 Subject: [PATCH 2/7] v0.5.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f0ed086..10c3614 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@brettm12345/react-dream", - "version": "0.5.2", + "version": "0.5.3", "description": "Fantasy Land type for React Components", "main": "dist/index.js", "types": "dist/index.d.ts", From 19fb2a121869cd990931655e68958608184753a3 Mon Sep 17 00:00:00 2001 From: brettm12345 Date: Sun, 19 Jan 2020 09:15:41 -0500 Subject: [PATCH 3/7] v0.5.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 10c3614..ce31d2a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@brettm12345/react-dream", - "version": "0.5.3", + "version": "0.5.4", "description": "Fantasy Land type for React Components", "main": "dist/index.js", "types": "dist/index.d.ts", From 77d5fc80d28b42ad35e2f162d5bc2edb314e8a97 Mon Sep 17 00:00:00 2001 From: brettm12345 Date: Sun, 19 Jan 2020 09:21:51 -0500 Subject: [PATCH 4/7] v0.5.5 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ce31d2a..4ee18be 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@brettm12345/react-dream", - "version": "0.5.4", + "version": "0.5.5", "description": "Fantasy Land type for React Components", "main": "dist/index.js", "types": "dist/index.d.ts", From d64380f0b029d2efaf73e006aedfdd6e6839991d Mon Sep 17 00:00:00 2001 From: brettm12345 Date: Sun, 19 Jan 2020 10:04:20 -0500 Subject: [PATCH 5/7] v0.5.7 --- package.json | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 4ee18be..d7e9afb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@brettm12345/react-dream", - "version": "0.5.5", + "version": "0.5.7", "description": "Fantasy Land type for React Components", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -41,15 +41,14 @@ "jsdom": "^11.12.0", "jsdom-global": "^3.0.2", "prettier": "^1.19.1", - "ramda": "^0.25.0", "react": "^16.0.0", "react-test-renderer": "^16.0.0", - "recompose": "^0.24.0", + "recompose": "^0.30.0", "washington": "^2.0.0-rc.3" }, "peerDependencies": { - "react": "^16.0.0", - "recompose": "^0.24.0" + "react": "^16.12.0", + "recompose": "^0.30.0" }, "dependencies": { "@hocs/with-debugger": "^0.1.0", From 01819faba390ab74f4cef57d5f2e8d86f36a1dc6 Mon Sep 17 00:00:00 2001 From: brettm12345 Date: Sun, 19 Jan 2020 10:06:29 -0500 Subject: [PATCH 6/7] v0.5.8 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d7e9afb..b6c3909 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@brettm12345/react-dream", - "version": "0.5.7", + "version": "0.5.8", "description": "Fantasy Land type for React Components", "main": "dist/index.js", "types": "dist/index.d.ts", From 7bcccbb80c802e2f4c75729d965b21b97d8f9346 Mon Sep 17 00:00:00 2001 From: brettm12345 Date: Mon, 20 Jan 2020 11:23:35 -0500 Subject: [PATCH 7/7] Typescript rewrite --- src/ReactDream.ts | 18 ++-------- src/index.ts | 2 -- src/internals/doContramap.tsx | 8 ++--- src/internals/doMap.ts | 7 ++-- src/internals/doPromap.ts | 7 ++-- src/internals/doRotate.ts | 32 +++-------------- src/internals/doScale.ts | 33 +++-------------- src/internals/doTransform.ts | 26 ++++++++++++++ src/internals/doTranslate.ts | 64 ++++++++++----------------------- src/partialApplication/debug.ts | 5 --- src/partialApplication/log.ts | 5 --- tsconfig.json | 11 +++--- yarn.lock | 37 ++++++++++++++----- 13 files changed, 103 insertions(+), 152 deletions(-) create mode 100644 src/internals/doTransform.ts delete mode 100644 src/partialApplication/debug.ts delete mode 100644 src/partialApplication/log.ts diff --git a/src/ReactDream.ts b/src/ReactDream.ts index 227f6e7..1aefbbd 100644 --- a/src/ReactDream.ts +++ b/src/ReactDream.ts @@ -2,8 +2,6 @@ import setDisplayName from "recompose/setDisplayName"; import recomposeDefaultProps from "recompose/defaultProps"; import setPropTypes from "recompose/setPropTypes"; import { flow, Endomorphism } from "fp-ts/lib/function"; -import withDebugger from "@hocs/with-debugger"; -import withLog from "@hocs/with-log"; import doAp from "./internals/doAp"; import doConcat from "./internals/doConcat"; import doContramap from "./internals/doContramap"; @@ -14,12 +12,8 @@ import doTranslate from "./internals/doTranslate"; import doScale from "./internals/doScale"; import styleFromProps from "./styleFromProps"; import { ComponentType, ValidationMap, CSSProperties } from "react"; -import { IO } from "fp-ts/lib/IO"; import { Hoc } from "./types"; -// ALGEBRAS -// ////////////////////////////////////////////////////////////////////////// // - interface EnhancedProps { style?: { transform?: string; @@ -57,15 +51,9 @@ export interface ReactDream

{ // fork : Component -> (Component -> a) -> a fork: (extractComponent: (Component: ComponentType

) => A) => A; - // debug : Component -> () -> IO ReactDream - debug: IO>; - // defaultProps : Component -> (Props) -> ReactDream defaultProps: (props: P) => ReactDream

; - // log : Component -> (Props -> String) -> IO ReactDream - log: (messageFromProps: (props: P) => string) => ReactDream

; - // name : Component -> String -> ReactDream name: (name: string) => ReactDream

; @@ -85,7 +73,9 @@ export interface ReactDream

{ style: (getStyleFromProps: (props: P) => CSSProperties) => ReactDream

; // translate : Component -> (Props -> [Number]) -> ReactDream - translate: (getTranslateFromProps: (props: P) => number[]) => ReactDream

; + translate: ( + getTranslateFromProps: (props: P) => Array + ) => ReactDream

; } const ReactDream =

(Component: ComponentType

): ReactDream

=> ({ @@ -105,13 +95,11 @@ const ReactDream =

(Component: ComponentType

): ReactDream

=> ({ ...props })), fork: extractComponent => extractComponent(Component), - debug: () => ReactDream(withDebugger(Component)), defaultProps: props => ReactDream( (recomposeDefaultProps(props)(Component) as unknown) as ComponentType

), name: flow(setDisplayName, ReactDream(Component).map), - log: messageFromProps => ReactDream(withLog(messageFromProps)(Component)), removeProps: (...propsToRemove) => ReactDream(Component).contramap(props => { // Nasty but efficient diff --git a/src/index.ts b/src/index.ts index dab2aaf..effb2a8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -11,10 +11,8 @@ export { default as ap } from "./partialApplication/ap"; export { default as chain } from "./partialApplication/chain"; export { default as concat } from "./partialApplication/concat"; export { default as contramap } from "./partialApplication/contramap"; -export { default as debug } from "./partialApplication/debug"; export { default as defaultProps } from "./partialApplication/defaultProps"; export { default as fork } from "./partialApplication/fork"; -export { default as log } from "./partialApplication/log"; export { default as map } from "./partialApplication/map"; export { default as name } from "./partialApplication/name"; export { default as promap } from "./partialApplication/promap"; diff --git a/src/internals/doContramap.tsx b/src/internals/doContramap.tsx index 8ca9c5b..61a6f68 100644 --- a/src/internals/doContramap.tsx +++ b/src/internals/doContramap.tsx @@ -1,19 +1,19 @@ -import React, { ComponentType } from "react"; -import compose from "recompose/compose"; +import React, { ComponentType, FC } from "react"; import getDisplayName from "recompose/getDisplayName"; import isReferentiallyTransparentFunctionComponent from "../isReferentiallyTransparentFunctionComponent"; +import { flow } from "fp-ts/lib/function"; // doContramap : (a -> Props) -> Component -> Component const doContramap = ( propsPreprocessor: (props: Outer) => Inner ) => (Component: ComponentType) => { const Enhanced = isReferentiallyTransparentFunctionComponent(Component) - ? compose(Component, propsPreprocessor) + ? flow(propsPreprocessor, Component) : (props: Outer) => ; (Enhanced as ComponentType).displayName = getDisplayName(Component); - return Enhanced as ComponentType; + return Enhanced as FC; }; export default doContramap; diff --git a/src/internals/doMap.ts b/src/internals/doMap.ts index 5bf1bf6..13206db 100644 --- a/src/internals/doMap.ts +++ b/src/internals/doMap.ts @@ -1,4 +1,7 @@ +import { Hoc } from "src/types"; +import { ComponentType } from "react"; + // (Component -> Component) -> Component -> Component -export default (higherOrderComponent: (component: C) => C) => ( - Component: C +export default

(higherOrderComponent: Hoc

) => ( + Component: ComponentType

) => higherOrderComponent(Component); diff --git a/src/internals/doPromap.ts b/src/internals/doPromap.ts index a687e67..381b1de 100644 --- a/src/internals/doPromap.ts +++ b/src/internals/doPromap.ts @@ -1,13 +1,12 @@ import doContramap from "./doContramap"; import doMap from "./doMap"; -import { Endomorphism } from "fp-ts/lib/function"; import { flow } from "fp-ts/lib/function"; -import { ComponentType } from "react"; +import { Hoc } from "src/types"; // doPromap : ((a -> Props), (Component -> Component)) -> Component -> Component const doPromap = ( propsPreprocessor: (props: Outer) => Inner, - higherOrderComponent: Endomorphism> -) => flow(doMap(higherOrderComponent), doContramap(propsPreprocessor)); + hoc: Hoc +) => flow(doMap(hoc), doContramap(propsPreprocessor)); export default doPromap; diff --git a/src/internals/doRotate.ts b/src/internals/doRotate.ts index 6c8e9ef..467f365 100644 --- a/src/internals/doRotate.ts +++ b/src/internals/doRotate.ts @@ -1,30 +1,8 @@ -import { pipe } from "fp-ts/lib/pipeable"; -import doContramap from "./doContramap"; -import { ComponentType } from "react"; +import doTransform from "./doTransform"; -const calculateTransform = (oldTransform: string | undefined) => ( - rotation: number -): string => +// doRotate : (Props -> Number) -> Component -> Component +export default doTransform(oldTransform => (rotation: number) => oldTransform ? `${oldTransform} rotate(${rotation}deg)` - : `rotate(${rotation}deg)`; - -interface EnhancedProps { - style?: { - transform?: string; - }; -} -// doRotate : (Props -> Number) -> Component -> Component -export default

( - getRotateFromProps: (props: P) => number -) => (Component: ComponentType

) => - doContramap(props => ({ - ...props, - style: { - ...props.style, - transform: pipe( - getRotateFromProps(props), - calculateTransform(props?.style?.transform) - ) - } - }))(Component); + : `rotate(${rotation}deg)` +); diff --git a/src/internals/doScale.ts b/src/internals/doScale.ts index 49bd03b..327873a 100644 --- a/src/internals/doScale.ts +++ b/src/internals/doScale.ts @@ -1,31 +1,6 @@ -import { pipe } from "fp-ts/lib/pipeable"; -import doContramap from "./doContramap"; -import { ComponentType } from "react"; - -const calculateTransform = (oldTransform: string | undefined) => ( - scaling: number -): string => - oldTransform ? `${oldTransform} scale(${scaling})` : `scale(${scaling})`; - -interface EnhancedProps { - style?: { - transform?: string; - }; -} +import doTransform from "./doTransform"; // doScale : (Props -> Number) -> Component -> Component -const doScale =

( - getScaleFromProps: (props: P) => number -) => (Component: ComponentType

) => - doContramap(props => ({ - ...props, - style: { - ...props.style, - transform: pipe( - getScaleFromProps(props), - calculateTransform(props?.style?.transform) - ) - } - }))(Component); - -export default doScale; +export default doTransform(oldTransform => (scaling: number) => + oldTransform ? `${oldTransform} scale(${scaling})` : `scale(${scaling})` +); diff --git a/src/internals/doTransform.ts b/src/internals/doTransform.ts new file mode 100644 index 0000000..6f0d3dd --- /dev/null +++ b/src/internals/doTransform.ts @@ -0,0 +1,26 @@ +import { pipe } from "fp-ts/lib/pipeable"; +import doContramap from "./doContramap"; + +export interface EnhancedProps { + style?: { + transform?: string; + }; +} + +const doTransform = ( + calculateTransform: ( + oldTransform: string | undefined + ) => (prop: T) => string | undefined +) =>

(getTransformFromProps: (props: P) => T) => + doContramap(props => ({ + ...props, + style: { + ...props.style, + transform: pipe( + getTransformFromProps(props), + calculateTransform(props?.style?.transform) + ) + } + })); + +export default doTransform; diff --git a/src/internals/doTranslate.ts b/src/internals/doTranslate.ts index 6db538f..e26ae1f 100644 --- a/src/internals/doTranslate.ts +++ b/src/internals/doTranslate.ts @@ -1,52 +1,26 @@ -import doContramap from "./doContramap"; -import { pipe } from "fp-ts/lib/pipeable"; -import { ComponentType } from "react"; +import doTransform from "./doTransform"; -const calculateTransform = (oldTransform: string | undefined) => ([ - x, - y, - z -]: Array): string | undefined => { - const old = (str: string): string => - oldTransform ? `${oldTransform} ${str}` : str; - - switch (true) { - case x != null && y != null && z != null: - return old(`translate3D(${x}px, ${y}px, ${z}px)`); - - case x != null && y != null: - return old(`translate(${x}px, ${y}px)`); +// doTranslate : (Props -> [Number]) -> Component -> Component +export default doTransform( + oldTransform => ([x, y, z]: Array) => { + const old = (str: string): string => + oldTransform ? `${oldTransform} ${str}` : str; - case z != null: - return old(`translateZ(${z}px)`); + switch (true) { + case x != null && y != null && z != null: + return old(`translate3D(${x}px, ${y}px, ${z}px)`); - case y != null: - return old(`translateY(${y}px)`); + case x != null && y != null: + return old(`translate(${x}px, ${y}px)`); - case x != null: - return old(`translateX(${x}px)`); - } -}; + case z != null: + return old(`translateZ(${z}px)`); -interface EnhancedProps { - style?: { - transform?: string; - }; -} + case y != null: + return old(`translateY(${y}px)`); -// doTranslate : (Props -> [Number]) -> Component -> Component -const doTranslate =

( - getTranslateFromProps: (props: P) => Array -) => (Component: ComponentType

) => - doContramap(props => ({ - ...props, - style: { - ...props.style, - transform: pipe( - getTranslateFromProps(props), - calculateTransform(props?.style?.transform) - ) + case x != null: + return old(`translateX(${x}px)`); } - }))(Component); - -export default doTranslate; + } +); diff --git a/src/partialApplication/debug.ts b/src/partialApplication/debug.ts deleted file mode 100644 index cc99eee..0000000 --- a/src/partialApplication/debug.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { ReactDream } from "src/ReactDream"; - -export default

(...f: Parameters["debug"]>) => ( - reactDream: ReactDream

-) => reactDream.debug(...f); diff --git a/src/partialApplication/log.ts b/src/partialApplication/log.ts deleted file mode 100644 index fbeb0b0..0000000 --- a/src/partialApplication/log.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { ReactDream } from "src/ReactDream"; - -export default

(...f: Parameters["log"]>) => ( - reactDream: ReactDream

-) => reactDream.log(...f); diff --git a/tsconfig.json b/tsconfig.json index 2e25615..d6f8d73 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,9 +9,9 @@ "forceConsistentCasingInFileNames": true, "isolatedModules": true, "outDir": "./dist", - "jsx": "preserve", - "lib": ["dom", "es2015", "es2017"], - "module": "esnext", + "jsx": "react", + "lib": ["dom", "es2015", "ESNext"], + "module": "CommonJS", "moduleResolution": "node", "noImplicitAny": true, "paths": { @@ -23,14 +23,13 @@ "noUnusedParameters": true, "preserveConstEnums": true, "removeComments": true, - "resolveJsonModule": true, "skipLibCheck": true, "sourceMap": true, "strict": true, "strictNullChecks": true, - "target": "esnext", + "target": "es5", "typeRoots": ["./src/@types", "./node_modules/@types"] }, - "include": ["./src/**/*"], + "include": ["./src"], "exclude": ["node_modules"] } diff --git a/yarn.lock b/yarn.lock index effe3d0..a7dc64f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,6 +2,13 @@ # yarn lockfile v1 +"@babel/runtime@^7.0.0": + version "7.8.3" + resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.8.3.tgz#0811944f73a6c926bb2ad35e918dcc1bfab279f1" + integrity sha512-fVHx1rzEmwB130VTkLnxR+HmxcTjGzH12LYQcFFoBwakMd3aOMD4OsRN7tGG/UOYE2ektgFrS8uACAoRk1CY0w== + dependencies: + regenerator-runtime "^0.13.2" + "@hocs/with-debugger@^0.1.0": version "0.1.0" resolved "https://registry.yarnpkg.com/@hocs/with-debugger/-/with-debugger-0.1.0.tgz#2a8c7f3dd9ae953fb3b0a736289a148b72b0b85c" @@ -1232,6 +1239,11 @@ hoist-non-react-statics@^1.0.0: resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-1.2.0.tgz#aa448cf0986d55cc40773b17174b7dd066cb7cfb" integrity sha1-qkSM8JhtVcxAdzsXF0t90GbLfPs= +hoist-non-react-statics@^2.3.1: + version "2.5.5" + resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-2.5.5.tgz#c5903cf409c0dfd908f388e619d86b9c1174cb47" + integrity sha512-rqcy4pJo55FTTLWt+bU8ukscqHeE/e9KWvsOW2b/a3afxQZhwkQdT1rPPCJ0rYXdj4vNcasY8zHTH+jF/qStxw== + home-or-tmp@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/home-or-tmp/-/home-or-tmp-2.0.0.tgz#e36c3f2d2cae7d746a857e38d18d5f32a7882db8" @@ -1839,10 +1851,6 @@ qs@~6.5.1: version "6.5.2" resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.2.tgz#cb3ae806e8740444584ef154ce8ee98d403f3e36" -ramda@^0.25.0: - version "0.25.0" - resolved "https://registry.yarnpkg.com/ramda/-/ramda-0.25.0.tgz#8fdf68231cffa90bc2f9460390a0cb74a29b29a9" - randomatic@^1.1.3: version "1.1.7" resolved "https://registry.yarnpkg.com/randomatic/-/randomatic-1.1.7.tgz#c7abe9cc8b87c0baa876b19fde83fd464797e38c" @@ -1864,6 +1872,11 @@ react-is@^16.8.1, react-is@^16.8.6: resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.12.0.tgz#2cc0fe0fba742d97fd527c42a13bec4eeb06241c" integrity sha512-rPCkf/mWBtKc97aLL9/txD8DZdemK0vkA3JMLShjlJB3Pj3s+lpf1KaBzMfQrAmhMQB0n1cU/SUGgKKBCe837Q== +react-lifecycles-compat@^3.0.2: + version "3.0.4" + resolved "https://registry.yarnpkg.com/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz#4f1a273afdfc8f3488a8c516bfda78f872352362" + integrity sha512-fBASbA6LnOU9dOU2eW7aQ8xmYBSXUIWr+UmF9b1efZBazGNO+rcXT/icdKnYm2pTwcRylVUYwW7H1PHfLekVzA== + react-test-renderer@^16.0.0: version "16.12.0" resolved "https://registry.yarnpkg.com/react-test-renderer/-/react-test-renderer-16.12.0.tgz#11417ffda579306d4e841a794d32140f3da1b43f" @@ -1914,13 +1927,16 @@ recompose@^0.23.4: hoist-non-react-statics "^1.0.0" symbol-observable "^1.0.4" -recompose@^0.24.0: - version "0.24.0" - resolved "https://registry.yarnpkg.com/recompose/-/recompose-0.24.0.tgz#262e93f974439eb17e7779824d88cce90492a5dd" +recompose@^0.30.0: + version "0.30.0" + resolved "https://registry.yarnpkg.com/recompose/-/recompose-0.30.0.tgz#82773641b3927e8c7d24a0d87d65aeeba18aabd0" + integrity sha512-ZTrzzUDa9AqUIhRk4KmVFihH0rapdCSMFXjhHbNrjAWxBuUD/guYlyysMnuHjlZC/KRiOKRtB4jf96yYSkKE8w== dependencies: + "@babel/runtime" "^7.0.0" change-emitter "^0.1.2" fbjs "^0.8.1" - hoist-non-react-statics "^1.0.0" + hoist-non-react-statics "^2.3.1" + react-lifecycles-compat "^3.0.2" symbol-observable "^1.0.4" regenerate@^1.2.1: @@ -1935,6 +1951,11 @@ regenerator-runtime@^0.11.0: version "0.11.1" resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz#be05ad7f9bf7d22e056f9726cee5017fbf19e2e9" +regenerator-runtime@^0.13.2: + version "0.13.3" + resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.3.tgz#7cf6a77d8f5c6f60eb73c5fc1955b2ceb01e6bf5" + integrity sha512-naKIZz2GQ8JWh///G7L3X6LaQUAMp2lvb1rvwwsURe/VXwD6VMfr+/1NuNw3ag8v2kY1aQ/go5SNn79O9JU7yw== + regenerator-transform@^0.10.0: version "0.10.1" resolved "https://registry.yarnpkg.com/regenerator-transform/-/regenerator-transform-0.10.1.tgz#1e4996837231da8b7f3cf4114d71b5691a0680dd"