diff --git a/changelog.md b/changelog.md index 54c7bc1d9..13dc05d21 100755 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,7 @@ ### Improvements +- [jss] Simplify cloneStyle function ([#1003](https://github.com/cssinjs/jss/pull/1003)) - [internal] Improve publish script for creating github release ([#999](https://github.com/cssinjs/jss/pull/999)) ### Bug fixes diff --git a/packages/jss/.size-snapshot.json b/packages/jss/.size-snapshot.json index 2df38f0fa..92662d827 100644 --- a/packages/jss/.size-snapshot.json +++ b/packages/jss/.size-snapshot.json @@ -1,30 +1,30 @@ { "dist/jss.js": { - "bundled": 59740, - "minified": 22374, - "gzipped": 6667 + "bundled": 58181, + "minified": 21925, + "gzipped": 6523 }, "dist/jss.min.js": { - "bundled": 58601, - "minified": 21513, - "gzipped": 6230 + "bundled": 57042, + "minified": 21067, + "gzipped": 6091 }, "dist/jss.cjs.js": { - "bundled": 54651, - "minified": 24090, - "gzipped": 6647 + "bundled": 53766, + "minified": 23846, + "gzipped": 6579 }, "dist/jss.esm.js": { - "bundled": 54135, - "minified": 23671, - "gzipped": 6560, + "bundled": 53270, + "minified": 23442, + "gzipped": 6498, "treeshaked": { "rollup": { - "code": 19192, - "import_statements": 314 + "code": 18995, + "import_statements": 281 }, "webpack": { - "code": 20665 + "code": 20418 } } } diff --git a/packages/jss/package.json b/packages/jss/package.json index 9f67af6f8..71f038447 100644 --- a/packages/jss/package.json +++ b/packages/jss/package.json @@ -42,7 +42,6 @@ "dependencies": { "@babel/runtime": "^7.0.0", "is-in-browser": "^1.1.3", - "symbol-observable": "^1.2.0", "tiny-warning": "^1.0.2" } } diff --git a/packages/jss/src/utils/cloneStyle.js b/packages/jss/src/utils/cloneStyle.js index 7b034cb2b..37d672625 100644 --- a/packages/jss/src/utils/cloneStyle.js +++ b/packages/jss/src/utils/cloneStyle.js @@ -1,44 +1,15 @@ -import $$observable from 'symbol-observable' import type {JssStyle} from '../types' -const {isArray} = Array - -// TODO: This should propably not be here, need to find a better place -const isObservable = value => value && value[$$observable] && value === value[$$observable]() +const plainObjectConstrurctor = {}.constructor export default function cloneStyle(style: JssStyle): JssStyle { - // Support empty values in case user ends up with them by accident. - if (style == null) return style - - // Support string value for SimpleRule. - const typeOfStyle = typeof style - - if (typeOfStyle === 'string' || typeOfStyle === 'number' || typeOfStyle === 'function') { - return style - } - - // It is a CSSTOM value. - // TODO will not work if instance comes from a different window. - if (global.CSSStyleValue && style instanceof global.CSSStyleValue) { - return style - } - - // Support array for FontFaceRule. - if (isArray(style)) return style.map(cloneStyle) - - // Support Observable styles. Observables are immutable, so we don't need to - // copy them. - if (isObservable(style)) return style + if (style == null || typeof style !== 'object') return style + if (Array.isArray(style)) return style.map(cloneStyle) + if (style.constructor !== plainObjectConstrurctor) return style const newStyle = {} for (const name in style) { - const value = style[name] - if (typeof value === 'object') { - newStyle[name] = cloneStyle(value) - continue - } - newStyle[name] = value + newStyle[name] = cloneStyle(style[name]) } - return newStyle }