-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathwithQuery.js
34 lines (29 loc) · 1.06 KB
/
withQuery.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import React from 'react';
import defaults from './defaults';
import { withTracker } from 'meteor/react-meteor-data';
import withReactiveQuery from './lib/withReactiveQuery';
import withQueryContainer from './lib/withQueryContainer';
import withStaticQuery from './lib/withStaticQuery';
import checkOptions from './lib/checkOptions';
export default function(handler, _config = {}) {
checkOptions(_config);
const config = Object.assign({}, defaults, _config);
return function(component) {
const queryContainer = withQueryContainer(component);
if (!config.reactive) {
const staticQueryContainer = withStaticQuery(config)(
queryContainer,
);
return function(props) {
const query = handler(props);
return React.createElement(staticQueryContainer, {
query,
props,
config,
});
};
} else {
return withReactiveQuery(handler, config, queryContainer);
}
};
}