Skip to content

Commit 1602b3c

Browse files
feat(interval-update): Component to update children components at intervals (#58)
* Implement higher order update on interval component, prepub hook * syntax fix * add support for custom decorator * chore(release): 1.42.5-update-interval.0 * Export update on interval * chore(release): 1.42.5-update-interval.1 * add runtime generators to support async * chore(release): 1.42.5-update-interval.2 * add options to "@babel/plugin-transform-runtime" * helpers set to false * add @babel/runtime for runtime support * Update doc
1 parent c15b3b3 commit 1602b3c

File tree

8 files changed

+283
-70
lines changed

8 files changed

+283
-70
lines changed

README.md

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ This is a set of components that is to be used to build a Quintype Node App. Thi
3232
* [WithPreview](#withpreview)
3333
* [WithSocialLogin](#withsociallogin)
3434
* [Review Rating](#review-rating)
35+
* [UpdateOnInterval](#UpdateOnInterval)
3536
* [Recommended Components that are not included](#recommended-components-that-are-not-included)
3637
* [Sliders](#sliders)
3738
* [Marquee for Breaking News](#marquee-for-breaking-news)
@@ -359,11 +360,12 @@ import { ResponsiveImage } from '@quintype/components';
359360
This component is used in more advanced usages if the aspect ratio is expected to change between screens
360361

361362
```javascript
363+
362364
import { ResponsiveSource } from '@quintype/components';
363365

364366
<figure className="story-grid-item-image">
365367
<picture>
366-
// Desktop Version
368+
<!--Desktop Version-->
367369
<ResponsiveSource media="(min-width: 1024px)"
368370
slug={props.story["hero-image-s3-key"]}
369371
metadata={props.story["hero-image-metadata"]}
@@ -372,7 +374,7 @@ import { ResponsiveSource } from '@quintype/components';
372374
sizes="(max-width: 500px) 98vw, (max-width: 768px) 48vw, 23vw"
373375
imgParams={{auto:['format', 'compress']}}/>
374376

375-
// Mobile Version
377+
<!--Mobile Version-->
376378
<ResponsiveImage
377379
slug={props.story["hero-image-s3-key"]}
378380
metadata={props.story["hero-image-metadata"]}
@@ -383,6 +385,7 @@ import { ResponsiveSource } from '@quintype/components';
383385
imgParams={{auto:['format', 'compress']}}/>
384386
</picture>
385387
</figure>
388+
386389
```
387390

388391
### SearchPageBase
@@ -562,6 +565,46 @@ import { ReviewRating } from '@quintype/components';
562565
```
563566
The component supports additional props which allows more customization, you can pass in props like size, color, count of stars or even change the render from star to a custom svg component. Refer to component src to know exact details of what is supported.
564567

568+
569+
### UpdateOnInterval
570+
571+
Serves as a wrapper used to update it's children via props while executing data loaders sent as props to the component.
572+
573+
Note : Dataloaders are made to be at an app level to keep the component generic, the return of Dataloaders are sent as props to its children.
574+
575+
```javascript
576+
import {UpdateOnInterval} from '@quintype/components';
577+
578+
<UpdateOnInterval>
579+
<!--Components to be refreshed at an interval-->
580+
</UpdateOnInterval>
581+
```
582+
583+
Props | Type | Description | Optional
584+
--- | --- | --- | ---
585+
`interval`| `number`(ms) | Sets the time, defaults to 30s | True
586+
`dataLoader`| `func` | Executes the dataloader, the return of which will be the data to the components children. The return should be an `object` | False
587+
`dataDecorator`| `func` | Sends the data from `dataLoader` to be customized, return of this this will be passed to the children. (`dataKey` is neglected if set) | False
588+
`dataKey`|`string`|The data returned from dataLoader will be decorated with this key, if not set dataLoader sends back data as returned | False
589+
590+
Example :
591+
```javascript
592+
function getData() {
593+
return fetch('/url/something')//...
594+
}
595+
596+
function prepareTime(data){
597+
return {time: data.eventTime};
598+
}
599+
```
600+
601+
```javascript
602+
<UpdateOnInterval interval={3000} dataLoader={() => getData()} dataDecorator={(data) => prepareTime(data)} >
603+
<SomeComponent>{this.props.time}</SomeComponent>
604+
</UpdateOnInterval>
605+
```
606+
607+
565608
## Recommended Components that are not included
566609

567610
### Sliders

babel.config.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ module.exports = function(api) {
77
"annotate-pure-calls",
88
"@babel/plugin-syntax-object-rest-spread",
99
"transform-react-remove-prop-types",
10-
"@babel/plugin-syntax-dynamic-import"
10+
"@babel/plugin-syntax-dynamic-import",
11+
["@babel/plugin-transform-runtime", {
12+
"corejs": false,
13+
"helpers": false,
14+
"regenerator": true,
15+
"useESModules": false
16+
}]
1117
];
1218

1319
if (env === 'esmodules') {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash -e
2+
3+
npm install
4+
git diff --quiet
5+
6+
BRANCH=$(git symbolic-ref --short HEAD)
7+
8+
if [ "$BRANCH" == 'master' ]
9+
then
10+
npx standard-version
11+
else
12+
npx standard-version --prerelease "$BRANCH" --skip.changelog=true
13+
fi
14+
15+
git push --follow-tags origin "$BRANCH"

0 commit comments

Comments
 (0)