Skip to content

Commit 50fbbbb

Browse files
committed
fix(component): A static WrappedComponent prop has been added to the HOC to aid testing. Additional
A static WrappedComponent prop has been added to the HOC to aid testing. Additionally the "conflictResolver" has been "moved" to the new "config" prop. The old parameter pass through method still works but can be considered deprecated.
1 parent cdfc04b commit 50fbbbb

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,10 @@ componentQueries({
177177
- `[monitorHeight]` (_Boolean_): If `true` then the height of your component will be tracked and provided within the `size` argument to your query functions. Defaults to `false`.
178178
- `[refreshRate]` (_Number_): The maximum frequency, in milliseconds, at which size changes should be recalculated when changes in your Component's rendered size are being detected. This must not be set to lower than 16. Defaults to `16`.
179179
- `[pure]` (_Boolean_): Indicates if your component should be considered "pure", i.e. it should only be rerendered if the result of your query functions change, or if new props are provided to the wrapped component. If you set it to false then the wrapped component will render _every_ time the size changes, even if it doesn't result in new query provided props. Defaults to `true`.
180-
- [`conflictResolver(prev, current, key) : Any`] \(_Function_): A custom function to use in order to resolve prop conflicts when two or more query functions return a prop with the same key. This gives you an opportunity to do custom resolution for special prop types, e.g. `className` where you could instead concat the conflicted values. The default implementation will return the value from the _last_ query function provided in the query array. Please read the respective section further down in the readme for more info and examples of this.
181-
- `prev` (_Any_): The value of the conflicted prop provided by the previously executed query function.
182-
- `current` (_Any_): The value of the conflicted prop provided by the most recently executed query function.
183-
- `key` (_Any_): The name of the prop which is in conflict.
180+
- [`conflictResolver(prev, current, key) : Any`] \(_Function_): A custom function to use in order to resolve prop conflicts when two or more query functions return a prop with the same key. This gives you an opportunity to do custom resolution for special prop types, e.g. `className` where you could instead concat the conflicted values. The default implementation will return the value from the _last_ query function provided in the query array. Please read the respective section further down in the readme for more info and examples of this.
181+
- `prev` (_Any_): The value of the conflicted prop provided by the previously executed query function.
182+
- `current` (_Any_): The value of the conflicted prop provided by the most recently executed query function.
183+
- `key` (_Any_): The name of the prop which is in conflict.
184184

185185
## Examples
186186

lib/react-component-queries.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/componentQueries.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,20 @@ function componentQueries(...params) {
4343
} else if (params[0].config) {
4444
// New school config style.
4545
pure = params[0].config.pure;
46-
const { monitorHeight, monitorWidth, refreshRate } = params[0].config;
46+
const {
47+
monitorHeight,
48+
monitorWidth,
49+
refreshRate,
50+
conflictResolver: _conflictResolver,
51+
} = params[0].config;
4752
sizeMeConfig = {
4853
monitorHeight: monitorHeight != null ? monitorHeight : defaultConfig.monitorHeight,
4954
monitorWidth: monitorWidth != null ? monitorWidth : defaultConfig.monitorWidth,
5055
refreshRate: refreshRate != null ? refreshRate : defaultConfig.refreshRate,
56+
conflictResolver: _conflictResolver,
5157
};
5258
}
53-
conflictResolver = params[0].conflictResolver || defaultConflictResolver;
59+
conflictResolver = conflictResolver || params[0].conflictResolver || defaultConflictResolver;
5460
invariant(
5561
typeof conflictResolver === 'function',
5662
'The conflict resolver you provide to ComponentQueries should be a function.'
@@ -95,6 +101,8 @@ function componentQueries(...params) {
95101
}).isRequired,
96102
};
97103

104+
static WrappedComponent = WrappedComponent;
105+
98106
state = {
99107
queryResult: {},
100108
}

test/ComponentQueries.test.js renamed to test/componentQueries.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,19 +104,23 @@ describeWithDOM('Given the ComponentQueries library', () => {
104104

105105
describe('And a custom config is provided', () => {
106106
it('Then the custom config should be given to SizeMe', () => {
107+
const conflictResolver = () => undefined;
108+
107109
componentQueries({
108110
queries: [() => ({})],
109111
config: {
110112
monitorHeight: true,
111113
monitorWidth: false,
112114
refreshRate: 200,
115+
conflictResolver,
113116
},
114117
})(() => <div />);
115118

116119
expect(sizeMeConfig).to.eql({
117120
monitorHeight: true,
118121
monitorWidth: false,
119122
refreshRate: 200,
123+
conflictResolver,
120124
});
121125
});
122126
});

0 commit comments

Comments
 (0)