Skip to content

Commit

Permalink
Use @emotion/memoize
Browse files Browse the repository at this point in the history
  • Loading branch information
Andarist committed Apr 7, 2018
1 parent d19b947 commit 263dc2f
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 51 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"eslint-plugin-standard": "^3.0.1",
"flow-bin": "^0.61.0",
"gatsby-react-router-scroll": "^1.0.7",
"get-lerna-packages": "^0.1.0",
"hoist-non-react-statics": "^2.3.1",
"jest": "^21.2.1",
"jest-cli": "^20.0.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/create-emotion-styled/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"watch": "rollup -c ../../rollup.config.js --watch"
},
"dependencies": {
"@emotion/is-prop-valid": "^0.5.2",
"@emotion/is-prop-valid": "^0.6.1",
"emotion-utils": "^9.1.0"
},
"peerDependencies": {
Expand Down
6 changes: 2 additions & 4 deletions packages/create-emotion-styled/src/utils.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
// @flow
import { memoize } from 'emotion-utils'
import isPropValid from '@emotion/is-prop-valid'
import type { Interpolations } from 'create-emotion'

export function setTheme(theme: Object) {
this.setState({ theme })
}

export const testPickPropsOnStringTag: (key: string) => boolean = memoize(
isPropValid
)
export const testPickPropsOnStringTag = isPropValid

export const testPickPropsOnComponent = (key: string) =>
key !== 'theme' && key !== 'innerRef'
export const testAlwaysTrue = () => true
Expand Down
3 changes: 3 additions & 0 deletions packages/emotion-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
"bugs": {
"url": "https://github.com/emotion-js/emotion/issues"
},
"dependencies": {
"@emotion/memoize": "^0.6.1"
},
"devDependencies": {
"babel-plugin-emotion": "^8.0.2-7",
"npm-run-all": "^4.0.2",
Expand Down
8 changes: 1 addition & 7 deletions packages/emotion-utils/src/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
// @flow

export const memoize = (fn: string => any) => {
const cache = {}
return (arg: string) => {
if (cache[arg] === undefined) cache[arg] = fn(arg)
return cache[arg]
}
}
export { default as memoize } from '@emotion/memoize'

export const STYLES_KEY = '__emotion_styles'

Expand Down
23 changes: 16 additions & 7 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ import babel from 'rollup-plugin-babel'
import alias from 'rollup-plugin-alias'
import cjs from 'rollup-plugin-commonjs'
import path from 'path'
import getLernaPackages from 'get-lerna-packages'
import { rollup as lernaAliases } from 'lerna-alias'

const flatMap = (iteratee, arr) => [].concat(...arr.map(iteratee))
const uniq = arr => [...new Set(arr)]

const pkg = require(path.resolve(process.cwd(), './package.json'))

const basePlugins = [
Expand Down Expand Up @@ -40,13 +44,18 @@ const baseConfig = {
const baseExternal = ['react', 'prop-types', 'preact']

const mainConfig = Object.assign({}, baseConfig, {
external: baseExternal.concat([
'emotion',
'emotion-utils',
'hoist-non-react-statics',
'stylis-rule-sheet',
'@emotion/is-prop-valid'
]),
external: uniq(
baseExternal.concat(
flatMap(dir => {
const {
dependencies = {},
peerDependencies = {}
} = require(`${dir}/package.json`)

return [...Object.keys(dependencies), ...Object.keys(peerDependencies)]
}, getLernaPackages())
)
),
plugins: basePlugins,
output: [
{ file: pkg.main, format: 'cjs' },
Expand Down
49 changes: 17 additions & 32 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -659,9 +659,15 @@
unist-util-remove-position "^1.1.1"
xtend "^4.0.1"

"@emotion/is-prop-valid@^0.5.2":
version "0.5.2"
resolved "https://registry.yarnpkg.com/@emotion/is-prop-valid/-/is-prop-valid-0.5.2.tgz#4f47717c2bcce8759e11997520e6bcb14326f54a"
"@emotion/is-prop-valid@^0.6.1":
version "0.6.1"
resolved "https://registry.yarnpkg.com/@emotion/is-prop-valid/-/is-prop-valid-0.6.1.tgz#98a255ac341064ddcf0d84f823b45ae9fb228f91"
dependencies:
"@emotion/memoize" "^0.6.1"

"@emotion/memoize@^0.6.1":
version "0.6.1"
resolved "https://registry.yarnpkg.com/@emotion/memoize/-/memoize-0.6.1.tgz#b2de5184e49f518b7115a5e6d0e727643ec531cf"

"@types/node@*":
version "8.0.49"
Expand Down Expand Up @@ -3524,14 +3530,6 @@ create-hmac@^1.1.0, create-hmac@^1.1.2, create-hmac@^1.1.4:
safe-buffer "^5.0.1"
sha.js "^2.4.8"

create-react-class@^15.6.0:
version "15.6.3"
resolved "https://registry.yarnpkg.com/create-react-class/-/create-react-class-15.6.3.tgz#2d73237fb3f970ae6ebe011a9e66f46dbca80036"
dependencies:
fbjs "^0.8.9"
loose-envify "^1.3.1"
object-assign "^4.1.1"

cross-env@^3.1.1:
version "3.2.4"
resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-3.2.4.tgz#9e0585f277864ed421ce756f81a980ff0d698aba"
Expand Down Expand Up @@ -5875,6 +5873,12 @@ get-caller-file@^1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-1.0.2.tgz#f702e63127e7e231c160a80c1554acb70d5047e5"

get-lerna-packages@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/get-lerna-packages/-/get-lerna-packages-0.1.0.tgz#f7cf4b358584d98f24cd931451e56ee9d37094e5"
dependencies:
glob "^7.1.2"

get-params@^0.1.2:
version "0.1.2"
resolved "https://registry.yarnpkg.com/get-params/-/get-params-0.1.2.tgz#bae0dfaba588a0c60d7834c0d8dc2ff60eeef2fe"
Expand Down Expand Up @@ -11032,16 +11036,7 @@ react-dev-utils@^4.2.1:
strip-ansi "3.0.1"
text-table "0.2.0"

react-dom@^15.6.0:
version "15.6.2"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-15.6.2.tgz#41cfadf693b757faf2708443a1d1fd5a02bef730"
dependencies:
fbjs "^0.8.9"
loose-envify "^1.1.0"
object-assign "^4.1.0"
prop-types "^15.5.10"

react-dom@^16.0.0, react-dom@^16.2.0:
react-dom@^15.6.0, react-dom@^16.0.0, react-dom@^16.2.0:
version "16.2.0"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.2.0.tgz#69003178601c0ca19b709b33a83369fe6124c044"
dependencies:
Expand Down Expand Up @@ -11155,17 +11150,7 @@ react-test-renderer@^16.2.0:
object-assign "^4.1.1"
prop-types "^15.6.0"

react@^15.6.0:
version "15.6.2"
resolved "https://registry.yarnpkg.com/react/-/react-15.6.2.tgz#dba0434ab439cfe82f108f0f511663908179aa72"
dependencies:
create-react-class "^15.6.0"
fbjs "^0.8.9"
loose-envify "^1.1.0"
object-assign "^4.1.0"
prop-types "^15.5.10"

react@^16.0.0, react@^16.2.0:
react@^15.6.0, react@^16.0.0, react@^16.2.0:
version "16.2.0"
resolved "https://registry.yarnpkg.com/react/-/react-16.2.0.tgz#a31bd2dab89bff65d42134fa187f24d054c273ba"
dependencies:
Expand Down

0 comments on commit 263dc2f

Please sign in to comment.