Skip to content

Commit

Permalink
Merge pull request #11 from interviewstreet/util
Browse files Browse the repository at this point in the history
[Refactor] Utility: Extract noop methods to util
  • Loading branch information
Progyan-APAC authored Nov 22, 2019
2 parents 6f4fcc2 + cdb32cf commit 61c1828
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-optimistic-toggle",
"version": "0.5.2",
"version": "0.5.3",
"description": "React component to build Optimistic UIs.",
"main": "lib/OptimisticToggle.js",
"repository": "https://github.com/interviewstreet/react-optimistic-toggle.git",
Expand Down
4 changes: 2 additions & 2 deletions src/OptimisticToggle.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @flow
import React, { Component, SyntheticEvent } from 'react';

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

type Props = {
/** Initial Value of the Checkbox */
Expand All @@ -19,7 +19,7 @@ type State = {
class OptimisticToggle extends Component<Props, State> {
static defaultProps: Props = {
initialValue: false,
action: noop,
action: noopPromise,
children: noop,
};

Expand Down
4 changes: 2 additions & 2 deletions src/useOptimisticToggle.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState, useRef, SyntheticEvent } from 'react';

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

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

function useOptimisticToggle({ initialValue = false, action = noop }: Props) {
function useOptimisticToggle({ initialValue = false, action = noopPromise }: Props) {
const [stateOptimistic, setStateOptimistic] = useState(initialValue);
const refCurrentPromise = useRef();
const refFailedCount = useRef(0);
Expand Down
10 changes: 10 additions & 0 deletions src/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* istanbul ignore next */
export function noop() {
/** No Operation */
}

/* istanbul ignore next */
export function noopPromise() {
/** No Operation that Returns a Promise */
return Promise.resolve();
}

0 comments on commit 61c1828

Please sign in to comment.