Skip to content

Commit 61c1828

Browse files
authored
Merge pull request #11 from interviewstreet/util
[Refactor] Utility: Extract noop methods to util
2 parents 6f4fcc2 + cdb32cf commit 61c1828

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-optimistic-toggle",
3-
"version": "0.5.2",
3+
"version": "0.5.3",
44
"description": "React component to build Optimistic UIs.",
55
"main": "lib/OptimisticToggle.js",
66
"repository": "https://github.com/interviewstreet/react-optimistic-toggle.git",

src/OptimisticToggle.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @flow
22
import React, { Component, SyntheticEvent } from 'react';
33

4-
const noop = () => {};
4+
import { noop, noopPromise } from './util';
55

66
type Props = {
77
/** Initial Value of the Checkbox */
@@ -19,7 +19,7 @@ type State = {
1919
class OptimisticToggle extends Component<Props, State> {
2020
static defaultProps: Props = {
2121
initialValue: false,
22-
action: noop,
22+
action: noopPromise,
2323
children: noop,
2424
};
2525

src/useOptimisticToggle.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useState, useRef, SyntheticEvent } from 'react';
22

3-
const noop = () => {};
3+
import { noopPromise } from './util';
44

55
type Props = {
66
/** Initial Value of the Checkbox */
@@ -9,7 +9,7 @@ type Props = {
99
action?: (toggleState: boolean, event: SyntheticEvent) => Promise<any>,
1010
};
1111

12-
function useOptimisticToggle({ initialValue = false, action = noop }: Props) {
12+
function useOptimisticToggle({ initialValue = false, action = noopPromise }: Props) {
1313
const [stateOptimistic, setStateOptimistic] = useState(initialValue);
1414
const refCurrentPromise = useRef();
1515
const refFailedCount = useRef(0);

src/util.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* istanbul ignore next */
2+
export function noop() {
3+
/** No Operation */
4+
}
5+
6+
/* istanbul ignore next */
7+
export function noopPromise() {
8+
/** No Operation that Returns a Promise */
9+
return Promise.resolve();
10+
}

0 commit comments

Comments
 (0)