From 8f3d77723dbbe557ddad1c064a6071c58207233b Mon Sep 17 00:00:00 2001 From: zetlen Date: Mon, 13 Aug 2018 13:27:10 -0500 Subject: [PATCH] chore: Update .babelrc and rm redundant files --- packages/venia-concept/.babelrc | 7 +-- .../src/util/__tests__/fromRenderProp.spec.js | 55 ---------------------- packages/venia-concept/src/util/fromRenderProp.js | 38 --------------- 3 files changed, 1 insertion(+), 99 deletions(-) delete mode 100644 packages/venia-concept/src/util/__tests__/fromRenderProp.spec.js delete mode 100644 packages/venia-concept/src/util/fromRenderProp.js diff --git a/packages/venia-concept/.babelrc b/packages/venia-concept/.babelrc index 74c9d8b..6ca049e 100644 --- a/packages/venia-concept/.babelrc +++ b/packages/venia-concept/.babelrc @@ -6,12 +6,7 @@ "transform-class-properties", "transform-es2015-modules-commonjs", "transform-object-rest-spread", - [ - "transform-react-jsx", - { - "pragma": "createElement" - } - ] + "transform-react-jsx" ] } } diff --git a/packages/venia-concept/src/util/__tests__/fromRenderProp.spec.js b/packages/venia-concept/src/util/__tests__/fromRenderProp.spec.js deleted file mode 100644 index 8b5e849..0000000 --- a/packages/venia-concept/src/util/__tests__/fromRenderProp.spec.js +++ /dev/null @@ -1,55 +0,0 @@ -import React from 'react'; -import { configure, shallow } from 'enzyme'; -import Adapter from 'enzyme-adapter-react-16'; - -import fromRenderProp, { filterProps } from '../fromRenderProp'; - -configure({ adapter: new Adapter() }); - -test('returns a component', () => { - const Div = fromRenderProp('div'); - - expect(Div).toBeInstanceOf(Function); -}); - -test('returns a basic component that renders', () => { - const Div = fromRenderProp('div'); - const wrapper = shallow(
foo
); - - expect(wrapper.prop('children')).toBe('foo'); -}); - -test('returns a composite component that renders', () => { - const Foo = props =>
; - const WrappedFoo = fromRenderProp(Foo); - const wrapper = shallow(foo); - - expect(wrapper.prop('children')).toBe('foo'); -}); - -test('excludes custom props for a basic component', () => { - const Div = fromRenderProp('div', ['foo']); - const wrapper = shallow(
); - - expect(wrapper.prop('foo')).toBeUndefined(); -}); - -test('includes custom props for a composite component', () => { - const Foo = props =>
; - const WrappedFoo = fromRenderProp(Foo, ['foo']); - const wrapper = shallow(); - - expect(wrapper.prop('foo')).toBe('bar'); -}); - -test('`filterProps` returns an object', () => { - expect(filterProps()).toEqual({}); -}); - -test('`filterProps` filters properties from an object', () => { - const input = { a: 0, b: 1 }; - const output = { b: 1 }; - const excludedProps = ['a']; - - expect(filterProps(input, excludedProps)).toEqual(output); -}); diff --git a/packages/venia-concept/src/util/fromRenderProp.js b/packages/venia-concept/src/util/fromRenderProp.js deleted file mode 100644 index 8f55d24..0000000 --- a/packages/venia-concept/src/util/fromRenderProp.js +++ /dev/null @@ -1,38 +0,0 @@ -// memoization cache -const cache = new Map(); - -export const filterProps = (props = {}, blacklist = []) => - Object.entries(props).reduce((r, [k, v]) => { - if (!blacklist.includes(k)) { - r[k] = v; - } - return r; - }, {}); - -const fromRenderProp = (elementType, customProps = []) => { - const isComposite = typeof elementType === 'function'; - - // if `elementType` is a function, it can be a component - if (isComposite) { - return elementType; - } - - // hash arguments for memoization - const key = `${elementType}//${customProps.join(',')}`; - - // only create a new component if not cached - // otherwise React will unmount on every render - if (!cache.has(key)) { - // create an SFC that renders a node of `elementType` - // and filter any props that shouldn't be written to the DOM - const Factory = props => - createElement(elementType, filterProps(props, customProps)); - - Factory.displayName = `${elementType}FromRenderProp`; - cache.set(key, Factory); - } - - return cache.get(key); -}; - -export default fromRenderProp; -- 2.15.2 (Apple Git-101.1)