Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bec83bd

Browse files
BinaryMusekuychaco
authored andcommitted
Use hoist-non-react-statics for hoisting static methods
1 parent 497bd4f commit bec83bd

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

lib/decorators/observe-model.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import hoistNonReactStatic from 'hoist-non-react-statics';
23

34
import ModelObserver from '../models/model-observer';
45

@@ -86,17 +87,7 @@ export default function ObserveModelDecorator(spec) {
8687
}
8788
}
8889

89-
Object.getOwnPropertyNames(Target).forEach(key => {
90-
if (typeof Target[key] === 'function') {
91-
Object.defineProperty(Wrapper, key, {
92-
value(...args) {
93-
return Target[key](...args);
94-
},
95-
enumerable: false,
96-
configurable: true,
97-
});
98-
}
99-
});
90+
hoistNonReactStatic(Wrapper, Target);
10091

10192
return Wrapper;
10293
};

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"etch": "0.8.0",
5151
"git-kitchen-sink": "1.17.0",
5252
"graphql": "^0.8.2",
53+
"hoist-non-react-statics": "^1.2.0",
5354
"keytar": "^3.0.2",
5455
"lodash.memoize": "^4.1.2",
5556
"moment": "^2.17.1",

test/decorators/observe-model.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ class TestModel {
3434
fetchData: model => model.getData(),
3535
})
3636
class TestComponent extends React.Component {
37+
static testMethod() {
38+
return 'Hi!';
39+
}
40+
3741
render() {
3842
return null;
3943
}
@@ -67,4 +71,8 @@ describe('ObserveModelDecorator', function() {
6771
await assert.async.equal(wrapper.find('TestComponent').prop('two'), 2);
6872
await assert.async.equal(wrapper.find('TestComponent').prop('testModel'), model2);
6973
});
74+
75+
it('hosts static methods', function() {
76+
assert.equal(TestComponent.testMethod(), 'Hi!');
77+
});
7078
});

0 commit comments

Comments
 (0)