Skip to content

Commit e890755

Browse files
committed
Reformat code with 4 spaces
1 parent a8a1b0e commit e890755

File tree

3 files changed

+87
-83
lines changed

3 files changed

+87
-83
lines changed

README.md

+71-71
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ The first function needs to return a valid `Query` or `NamedQuery` from Grapher.
1919
```js
2020
// This is a query
2121
const query = createQuery({
22-
users: {
23-
emails: 1
24-
}
22+
users: {
23+
emails: 1,
24+
},
2525
});
2626

2727
// This is a named query
2828
const query = createQuery('usersWithEmails', {
29-
users: {
30-
emails: 1
31-
}
29+
users: {
30+
emails: 1,
31+
},
3232
});
3333
```
3434

@@ -100,25 +100,25 @@ import React from 'react';
100100
import { withQuery } from 'meteor/cultofcoders:grapher-react';
101101

102102
const PostList = ({ data, isLoading, error }) => {
103-
if (isLoading) {
104-
return <div>Loading</div>;
105-
}
106-
107-
if (error) {
108-
return <div>{error.reason}</div>;
109-
}
110-
111-
return (
112-
<div>
113-
{data.map(post => (
114-
<li key={post._id}>{post.title}</li>
115-
))}
116-
</div>
117-
);
103+
if (isLoading) {
104+
return <div>Loading</div>;
105+
}
106+
107+
if (error) {
108+
return <div>{error.reason}</div>;
109+
}
110+
111+
return (
112+
<div>
113+
{data.map(post => (
114+
<li key={post._id}>{post.title}</li>
115+
))}
116+
</div>
117+
);
118118
};
119119

120120
export default withQuery(props => {
121-
return getPostLists.clone();
121+
return getPostLists.clone();
122122
})(PostList);
123123
```
124124

@@ -168,29 +168,29 @@ The first example uses the query non-reactively (because that is the default). B
168168
```jsx harmony
169169
// ...
170170
export default withQuery(
171-
props => {
172-
return getPostLists.clone();
173-
},
174-
{ reactive: true }
171+
props => {
172+
return getPostLists.clone();
173+
},
174+
{ reactive: true },
175175
)(PostList);
176176
```
177177

178178
As mentioned above, the props received are passed down to the component we wrap, meaning:
179179

180180
```jsx harmony
181181
const PostList = ({ data, something }) => {
182-
return <div>Something is true!</div>;
182+
return <div>Something is true!</div>;
183183
};
184184

185185
const Container = withQuery(
186-
props => {
187-
return getPostLists.clone();
188-
},
189-
{ reactive: true }
186+
props => {
187+
return getPostLists.clone();
188+
},
189+
{ reactive: true },
190190
)(PostList);
191191

192192
export default function() {
193-
return <Container something={true} />;
193+
return <Container something={true} />;
194194
}
195195
```
196196

@@ -204,63 +204,63 @@ import React from 'react';
204204
import { withQuery } from 'meteor/cultofcoders:grapher-react';
205205

206206
const PostList = ({ data, isLoading, error, refetch }) => {
207-
return (
208-
<div>
209-
<a onClick={refetch}>Reload the data</a>
210-
{/* Rest of the component */}
211-
</div>
212-
);
207+
return (
208+
<div>
209+
<a onClick={refetch}>Reload the data</a>
210+
{/* Rest of the component */}
211+
</div>
212+
);
213213
};
214214

215215
export default withQuery(
216-
props => {
217-
return getPostLists.clone();
218-
},
219-
{ reactive: false }
216+
props => {
217+
return getPostLists.clone();
218+
},
219+
{ reactive: false },
220220
)(PostList);
221221
```
222222

223223
If you container wraps a single object, and not a list of objects, you can configure your query like this:
224224

225225
```jsx harmony
226226
const UserProfile = ({ data, isLoading, error }) => {
227-
return <div>{data.email}</div>;
227+
return <div>{data.email}</div>;
228228
};
229229

230230
export default withQuery(
231-
props => {
232-
return getUserProfile.clone({ userId: props.userId });
233-
},
234-
{
235-
single: true
236-
}
231+
props => {
232+
return getUserProfile.clone({ userId: props.userId });
233+
},
234+
{
235+
single: true,
236+
},
237237
)(UserProfile);
238238
```
239239

240240
You will find yourself repeating the same code over and over again for when the query is loading or it has an error. For this you can do:
241241

242242
```jsx harmony
243243
function ErrorComponent({ error }) {
244-
return <div>{error.reason}</div>;
244+
return <div>{error.reason}</div>;
245245
}
246246

247247
function LoadingComponent() {
248-
return <div>Please wait...</div>;
248+
return <div>Please wait...</div>;
249249
}
250250

251251
const UserProfile = ({ data }) => {
252-
return <div>{data.email}</div>;
252+
return <div>{data.email}</div>;
253253
};
254254

255255
export default withQuery(
256-
props => {
257-
return getUserProfile.clone({ userId: props.userId });
258-
},
259-
{
260-
single: true,
261-
errorComponent: ErrorComponent,
262-
loadingComponent: LoadingComponent
263-
}
256+
props => {
257+
return getUserProfile.clone({ userId: props.userId });
258+
},
259+
{
260+
single: true,
261+
errorComponent: ErrorComponent,
262+
loadingComponent: LoadingComponent,
263+
},
264264
)(UserProfile);
265265
```
266266

@@ -272,23 +272,23 @@ To make things even more simple, you can globally define these rules, and all th
272272
import { setDefaults } from 'meteor/cultofcoders:grapher-react';
273273

274274
setDefaults({
275-
reactive: false, // you can default it to true
276-
single: false, // doesn't make sense to default this to true
277-
errorComponent: ErrorComponent,
278-
loadingComponent: LoadingComponent
275+
reactive: false, // you can default it to true
276+
single: false, // doesn't make sense to default this to true
277+
errorComponent: ErrorComponent,
278+
loadingComponent: LoadingComponent,
279279
});
280280
```
281281

282282
You can override the defaults at the `withQuery` level, for example you want different `error` and `loading` components, you can simply do:
283283

284284
```jsx harmony
285285
export default withQuery(
286-
props => {
287-
return getUserProfile.clone({ userId: props.userId });
288-
},
289-
{
290-
errorComponent: null,
291-
loadingComponent: AnotherLoadingComponent
292-
}
286+
props => {
287+
return getUserProfile.clone({ userId: props.userId });
288+
},
289+
{
290+
errorComponent: null,
291+
loadingComponent: AnotherLoadingComponent,
292+
},
293293
)(UserProfile);
294294
```

lib/withStaticQuery.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import getDisplayName from './getDisplayName';
33

44
export default function withStaticQueryContainer(config) {
5-
return function (WrappedComponent) {
5+
return function(WrappedComponent) {
66
/**
77
* We use it like this so we can have naming inside React Dev Tools
88
* This is a standard pattern in HOCs
@@ -26,7 +26,7 @@ export default function withStaticQueryContainer(config) {
2626
if (config.pollingMs) {
2727
this.pollingInterval = setInterval(() => {
2828
this.fetch(query);
29-
}, config.pollingMs)
29+
}, config.pollingMs);
3030
}
3131
}
3232

@@ -41,7 +41,7 @@ export default function withStaticQueryContainer(config) {
4141
error,
4242
data: [],
4343
isLoading: false,
44-
})
44+
});
4545
} else {
4646
this.setState({
4747
error: null,
@@ -77,8 +77,10 @@ export default function withStaticQueryContainer(config) {
7777
}
7878
}
7979

80-
GrapherStaticQueryContainer.displayName = `StaticQuery(${getDisplayName(WrappedComponent)})`;
80+
GrapherStaticQueryContainer.displayName = `StaticQuery(${getDisplayName(
81+
WrappedComponent,
82+
)})`;
8183

8284
return GrapherStaticQueryContainer;
83-
}
84-
}
85+
};
86+
}

withQuery.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,22 @@ import checkOptions from './lib/checkOptions';
99
export default function(handler, _config = {}) {
1010
checkOptions(_config);
1111
const config = Object.assign({}, defaults, _config);
12-
12+
1313
return function(component) {
1414
const queryContainer = withQueryContainer(component);
15-
15+
1616
if (!config.reactive) {
17-
const staticQueryContainer = withStaticQuery(config)(queryContainer);
18-
17+
const staticQueryContainer = withStaticQuery(config)(
18+
queryContainer,
19+
);
20+
1921
return function(props) {
2022
const query = handler(props);
21-
23+
2224
return React.createElement(staticQueryContainer, {
2325
query,
2426
props,
25-
config
27+
config,
2628
});
2729
};
2830
} else {

0 commit comments

Comments
 (0)