Skip to content
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

hoist static functions in withLocalization #430

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions fluent-gecko/vendor_config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import nodeResolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import bundleConfig from '../bundle_config';

export default Object.assign({}, bundleConfig, {
Expand Down Expand Up @@ -30,5 +31,10 @@ export default Object.assign({}, bundleConfig, {
],
plugins: [
nodeResolve(),
commonjs({
namedExports: {
"hoist-non-react-statics": [ "hoistNonReactStatics" ]
}
})
]
});
1 change: 1 addition & 0 deletions fluent-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"dependencies": {
"cached-iterable": "^0.2.1",
"@fluent/sequence": "0.4.0",
"hoist-non-react-statics": "^3.0.0",
"prop-types": "^15.6.0"
},
"peerDependencies": {
Expand Down
4 changes: 3 additions & 1 deletion fluent-react/src/with_localization.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { createElement, Component } from "react";

import { isReactLocalization } from "./localization";

import hoistNonReactStatics from "hoist-non-react-statics";

export default function withLocalization(Inner) {
class WithLocalization extends Component {
componentDidMount() {
Expand Down Expand Up @@ -60,7 +62,7 @@ export default function withLocalization(Inner) {
l10n: isReactLocalization
};

return WithLocalization;
return hoistNonReactStatics(WithLocalization, Inner);
}

function displayName(component) {
Expand Down
16 changes: 14 additions & 2 deletions fluent-react/test/with_localization_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ import { FluentBundle, FluentResource } from '../../fluent-bundle/src';
import ReactLocalization from '../src/localization';
import { withLocalization, LocalizationProvider } from '../src';

function DummyComponent() {
return <div />;
class DummyComponent extends React.Component {
static doStaticThing() {
return "done";
}

render() {
return <div />;
}
}

suite('withLocalization', function() {
Expand Down Expand Up @@ -123,4 +129,10 @@ bar = BAR {$arg}
wrapper.update();
assert.strictEqual(wrapper.text(), 'BAR');
})

test('static function is hoisted onto the wrapped component', function() {
const EnhancedComponent = withLocalization(DummyComponent);
const result = EnhancedComponent.doStaticThing();
assert.strictEqual(result, "done");
})
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"prettyjson": "^1.2.1",
"rollup": "^1.9.3",
"rollup-plugin-babel": "^4.3.2",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-node-resolve": "^4.2.2"
}
}