Skip to content

Hoist non-react static properties #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"theming"
],
"dependencies": {
"hoist-non-react-statics": "^1.2.0",
"invariant": "^2.2.1"
},
"devDependencies": {
Expand Down
3 changes: 2 additions & 1 deletion src/components/themr.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { Component, PropTypes } from 'react'
import hoistNonReactStatics from 'hoist-non-react-statics'
import invariant from 'invariant'

/**
Expand Down Expand Up @@ -149,7 +150,7 @@ export default (componentName, localTheme, options = {}) => (ThemedComponent) =>

Themed[THEMR_CONFIG] = config

return Themed
return hoistNonReactStatics(Themed, ThemedComponent)
}

/**
Expand Down
11 changes: 11 additions & 0 deletions test/components/themr.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
14 changes: 9 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -1195,14 +1199,10 @@ es6-weak-map@^2.0.1:
es6-iterator "2"
es6-symbol "3"

[email protected], escape-string-regexp@^1.0.5:
[email protected], 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"
Expand Down Expand Up @@ -1624,6 +1624,10 @@ [email protected]:
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"
Expand Down