forked from patternfly/patternfly-react
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(extensions): Create local helpers to lessen dependencies (pattern…
…fly#985) Pulling in the patternfly-react helpers bring in more dependencies than are needed. This PR duplicates some of the small utility helpers in order to reduce the footprint of the extensions package.
- Loading branch information
1 parent
35c5021
commit 3e1d440
Showing
9 changed files
with
63 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
packages/patternfly-3/patternfly-react-extensions/src/common/helpers.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import React from 'react'; | ||
|
||
/** Implementation of the debounce function */ | ||
export const debounce = (func, wait) => { | ||
let timeout; | ||
function innerFunc(...args) { | ||
const context = this; | ||
clearTimeout(timeout); | ||
timeout = setTimeout(() => func.apply(context, args), wait); | ||
} | ||
return innerFunc; | ||
}; | ||
|
||
/** Returns a subset of the given object including only the given keys, with values optionally replaced by a fn. */ | ||
export const selectKeys = (obj, keys, fn = val => val) => | ||
keys.reduce((values, key) => ({ ...values, [key]: fn(obj[key]) }), {}); | ||
|
||
/** Returns a subset of the given object with a validator function applied to its keys. */ | ||
export const filterKeys = (obj, validator) => selectKeys(obj, Object.keys(obj).filter(validator)); | ||
|
||
/** Returns a subset of the given object with the given keys left out. */ | ||
export const excludeKeys = (obj, keys) => filterKeys(obj, key => !keys.includes(key)); | ||
|
||
/** Returns the given React children prop as a regular array of React nodes. */ | ||
export const childrenToArray = children => | ||
children && React.Children.count(children) > 0 && React.Children.toArray(children); | ||
|
||
/** Returns true if the component has the desired displayName value */ | ||
export const hasDisplayName = (component, displayName) => | ||
component && component.type && component.type.displayName === displayName; | ||
|
||
export const noop = Function.prototype; | ||
|
||
export const helpers = { | ||
debounce, | ||
selectKeys, | ||
filterKeys, | ||
excludeKeys, | ||
childrenToArray, | ||
hasDisplayName, | ||
noop | ||
}; | ||
|
||
export default helpers; |
3 changes: 2 additions & 1 deletion
3
...y-3/patternfly-react-extensions/src/components/CatalogTileView/CatalogTileViewCategory.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...y-3/patternfly-react-extensions/src/components/FilterSidePanel/FilterSidePanelCategory.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
packages/patternfly-3/patternfly-react-extensions/src/components/TableGrid/TableGrid.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...atternfly-3/patternfly-react-extensions/src/components/TableGrid/TableGridColumnHeader.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
packages/patternfly-3/patternfly-react-extensions/src/components/TableGrid/TableGridHead.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
packages/patternfly-3/patternfly-react-extensions/src/components/TableGrid/TableGridRow.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters