From e05afb7367e111b43f8a66b22254372e051516c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Mu=C3=B1oz?= Date: Tue, 14 Mar 2017 13:21:51 -0400 Subject: [PATCH] Hoist non-react static properties --- package.json | 1 + src/components/themr.js | 3 ++- test/components/themr.spec.js | 11 +++++++++++ yarn.lock | 14 +++++++++----- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 9e2450a..888c201 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "theming" ], "dependencies": { + "hoist-non-react-statics": "^1.2.0", "invariant": "^2.2.1" }, "devDependencies": { diff --git a/src/components/themr.js b/src/components/themr.js index f4c5fd2..5380b9d 100644 --- a/src/components/themr.js +++ b/src/components/themr.js @@ -1,4 +1,5 @@ import React, { Component, PropTypes } from 'react' +import hoistNonReactStatics from 'hoist-non-react-statics' import invariant from 'invariant' /** @@ -149,7 +150,7 @@ export default (componentName, localTheme, options = {}) => (ThemedComponent) => Themed[THEMR_CONFIG] = config - return Themed + return hoistNonReactStatics(Themed, ThemedComponent) } /** diff --git a/test/components/themr.spec.js b/test/components/themr.spec.js index 0a78022..6cbb476 100644 --- a/test/components/themr.spec.js +++ b/test/components/themr.spec.js @@ -349,6 +349,17 @@ describe('Themr decorator function', () => { expect(Foo.defaultProps.foo).toBe(defaultProps.foo) }) + it('should copy non-react statics from ThemedComponent', () => { + const meta = { name: 'Foo' } + + @themr('Foo') + class Foo extends Component { + static meta = meta; + } + + expect(Foo.meta.name).toBe(meta.name) + }) + it('should not wrap multiple time if used with already wrapped component with the same key', () => { const foo = { foo: 'foo' diff --git a/yarn.lock b/yarn.lock index 1681967..62bf884 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,6 +2,10 @@ # yarn lockfile v1 +"@types/react@~15.0.4": + version "15.0.16" + resolved "https://registry.yarnpkg.com/@types/react/-/react-15.0.16.tgz#78e39511a9cfcabf7f74ecd55180522f4290a0c1" + abab@^1.0.0: version "1.0.3" resolved "https://registry.yarnpkg.com/abab/-/abab-1.0.3.tgz#b81de5f7274ec4e756d797cd834f303642724e5d" @@ -1195,14 +1199,10 @@ es6-weak-map@^2.0.1: es6-iterator "2" es6-symbol "3" -escape-string-regexp@1.0.5, escape-string-regexp@^1.0.5: +escape-string-regexp@1.0.5, escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.5: version "1.0.5" resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" -escape-string-regexp@^1.0.2: - version "1.0.2" - resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.2.tgz#4dbc2fe674e71949caf3fb2695ce7f2dc1d9a8d1" - escodegen@^1.6.1: version "1.8.1" resolved "https://registry.yarnpkg.com/escodegen/-/escodegen-1.8.1.tgz#5a5b53af4693110bebb0867aa3430dd3b70a1018" @@ -1624,6 +1624,10 @@ hoek@2.x.x: version "2.16.3" resolved "https://registry.yarnpkg.com/hoek/-/hoek-2.16.3.tgz#20bb7403d3cea398e91dc4710a8ff1b8274a25ed" +hoist-non-react-statics@^1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-1.2.0.tgz#aa448cf0986d55cc40773b17174b7dd066cb7cfb" + 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"