Skip to content

Commit 8f49f57

Browse files
committed
chore: add 0.4.1 version that restores the without args version to follow semver
1 parent 7da12e3 commit 8f49f57

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
22
"name": "react-with-spinner",
3-
"version": "0.4.0",
3+
"version": "0.4.1",
44
"description": "",
55
"main": "dist/src/index.js",
6+
"types": "dist/src/index.d.ts",
67
"scripts": {
78
"build": "tscomp build",
89
"watch": "tscomp watch",

src/__snapshots__/index.test.tsx.snap

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,13 @@ exports[`withSpinner should support custom nested loading property 1`] = `
138138
</withSpinner(DisplayComponent)>
139139
</_class3>
140140
`;
141+
142+
exports[`withSpinner should work without any args 1`] = `
143+
<DefaultSpinner
144+
data={
145+
Object {
146+
"loading": true,
147+
}
148+
}
149+
/>
150+
`;

src/index.test.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,22 @@ const Loading = () => <span>Loading...</span>
1111
jest.useFakeTimers()
1212

1313
describe('withSpinner', () => {
14+
it('should work without any args', () => {
15+
const Component = compose(
16+
WrappedComponent => props => <WrappedComponent {...props} data={{loading: true}} />,
17+
withSpinner(),
18+
)(() => <div></div>)
19+
20+
const wrapper = shallow(<Component />).first().shallow()
21+
22+
expect(wrapper.type()).toBeNull()
23+
24+
// Run timer so it passes withSpinner timeout
25+
jest.runTimersToTime(100)
26+
wrapper.update()
27+
28+
expect(toJson(wrapper)).toMatchSnapshot()
29+
})
1430
it('should render spinner if loading is true', () => {
1531
const Component = compose(
1632
WrappedComponent => props => <WrappedComponent {...props} data={{loading: true}} />,

src/index.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ export type Properties = {
5151
emptyComponent?: ReactType
5252
}
5353

54+
const DefaultSpinner = () => <div>Loading...</div>
55+
5456
function getDataProperty(propName: string|Array<string>, props: Properties) {
5557
return Array.isArray(propName)
5658
? path(propName, props)
@@ -60,11 +62,11 @@ function getDataProperty(propName: string|Array<string>, props: Properties) {
6062
export const withSpinner = ({
6163
prop = 'data', timeout = 100,
6264
handleError = true, partial = false,
63-
skipErrors, spinnerProps,
65+
skipErrors = false, spinnerProps = {},
6466
errorComponent: ErrorComponent = null,
65-
spinnerComponent: Spinner,
67+
spinnerComponent: Spinner = DefaultSpinner,
6668
emptyComponent: EmptyComponent = null,
67-
}: Properties): any => WrappedComponent =>
69+
}: Properties = {} as Properties): any => WrappedComponent =>
6870
class extends Component<Properties, {showSpinner: boolean}> {
6971
static displayName = wrapDisplayName(WrappedComponent, 'withSpinner')
7072

@@ -101,7 +103,7 @@ export const withSpinner = ({
101103
if (this.state.showSpinner) return <Spinner {...spinnerProps} {...this.props} />
102104

103105
if (this.timeout === null) {
104-
this.timeout = setTimeout(() => {
106+
this.timeout = window.setTimeout(() => {
105107
this.setState({showSpinner: true})
106108
}, timeout)
107109
}

0 commit comments

Comments
 (0)