Skip to content

Commit bad51e4

Browse files
ctumolosusdavid-slayte
authored andcommitted
Hoist non-react static properties (javivelasco#51)
1 parent e449090 commit bad51e4

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"theming"
2525
],
2626
"dependencies": {
27+
"hoist-non-react-statics": "^1.2.0",
2728
"invariant": "^2.2.1"
2829
},
2930
"devDependencies": {

src/components/themr.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { Component, PropTypes } from 'react'
2+
import hoistNonReactStatics from 'hoist-non-react-statics'
23
import invariant from 'invariant'
34

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

150151
Themed[THEMR_CONFIG] = config
151152

152-
return Themed
153+
return hoistNonReactStatics(Themed, ThemedComponent)
153154
}
154155

155156
/**

test/components/themr.spec.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,17 @@ describe('Themr decorator function', () => {
349349
expect(Foo.defaultProps.foo).toBe(defaultProps.foo)
350350
})
351351

352+
it('should copy non-react statics from ThemedComponent', () => {
353+
const meta = { name: 'Foo' }
354+
355+
@themr('Foo')
356+
class Foo extends Component {
357+
static meta = meta;
358+
}
359+
360+
expect(Foo.meta.name).toBe(meta.name)
361+
})
362+
352363
it('should not wrap multiple time if used with already wrapped component with the same key', () => {
353364
const foo = {
354365
foo: 'foo'

yarn.lock

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
# yarn lockfile v1
33

44

5+
"@types/react@~15.0.4":
6+
version "15.0.16"
7+
resolved "https://registry.yarnpkg.com/@types/react/-/react-15.0.16.tgz#78e39511a9cfcabf7f74ecd55180522f4290a0c1"
8+
59
abab@^1.0.0:
610
version "1.0.3"
711
resolved "https://registry.yarnpkg.com/abab/-/abab-1.0.3.tgz#b81de5f7274ec4e756d797cd834f303642724e5d"
@@ -1195,14 +1199,10 @@ es6-weak-map@^2.0.1:
11951199
es6-iterator "2"
11961200
es6-symbol "3"
11971201

1198-
[email protected], escape-string-regexp@^1.0.5:
1202+
[email protected], escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.5:
11991203
version "1.0.5"
12001204
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
12011205

1202-
escape-string-regexp@^1.0.2:
1203-
version "1.0.2"
1204-
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.2.tgz#4dbc2fe674e71949caf3fb2695ce7f2dc1d9a8d1"
1205-
12061206
escodegen@^1.6.1:
12071207
version "1.8.1"
12081208
resolved "https://registry.yarnpkg.com/escodegen/-/escodegen-1.8.1.tgz#5a5b53af4693110bebb0867aa3430dd3b70a1018"
@@ -1624,6 +1624,10 @@ [email protected]:
16241624
version "2.16.3"
16251625
resolved "https://registry.yarnpkg.com/hoek/-/hoek-2.16.3.tgz#20bb7403d3cea398e91dc4710a8ff1b8274a25ed"
16261626

1627+
hoist-non-react-statics@^1.2.0:
1628+
version "1.2.0"
1629+
resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-1.2.0.tgz#aa448cf0986d55cc40773b17174b7dd066cb7cfb"
1630+
16271631
home-or-tmp@^2.0.0:
16281632
version "2.0.0"
16291633
resolved "https://registry.yarnpkg.com/home-or-tmp/-/home-or-tmp-2.0.0.tgz#e36c3f2d2cae7d746a857e38d18d5f32a7882db8"

0 commit comments

Comments
 (0)