Skip to content

Commit c7e1500

Browse files
ethansharM-i-k-e-l
andauthored
Change how we extract a component props (#951)
* Change how we extract a component props * Update src/commons/modifiers.ts Co-authored-by: Miki <[email protected]> Co-authored-by: Miki <[email protected]>
1 parent 2940d93 commit c7e1500

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

src/commons/modifiers.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,10 @@ export function extractModifierProps(props: Dictionary<any>) {
304304
return modifierProps;
305305
}
306306

307+
/**
308+
* TODO:
309+
* @deprecated switch to Modifiers#extractComponentProps
310+
*/
307311
export function extractOwnProps(props: Dictionary<any>, ignoreProps: string[]) {
308312
//@ts-ignore
309313
const ownPropTypes = this.propTypes;
@@ -315,6 +319,16 @@ export function extractOwnProps(props: Dictionary<any>, ignoreProps: string[]) {
315319
return ownProps;
316320
}
317321

322+
export function extractComponentProps(component: any, props: Dictionary<any>, ignoreProps: string[]) {
323+
const componentPropTypes = component.propTypes;
324+
const componentProps = _.chain(props)
325+
.pickBy((_value, key) => _.includes(Object.keys(componentPropTypes), key))
326+
.omit(ignoreProps)
327+
.value();
328+
329+
return componentProps;
330+
}
331+
318332
//@ts-ignore
319333
export function getThemeProps(props = this.props, context = this.context) {
320334
//@ts-ignore

src/components/picker/PickerDialog.android.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import PropTypes from 'prop-types';
44
import _ from 'lodash';
55

66
import {BaseComponent} from '../../commons';
7+
import {extractComponentProps} from '../../commons/modifiers';
78
import Dialog from '../dialog';
89
import View from '../view';
910
import Text from '../text';
@@ -80,7 +81,7 @@ class PickerDialog extends BaseComponent {
8081
}
8182

8283
render() {
83-
const dialogProps = Dialog.extractOwnProps(this.props);
84+
const dialogProps = extractComponentProps(Dialog, this.props);
8485
return (
8586
<Dialog {...dialogProps} migrate height="50%" width="77%">
8687
<View style={styles.dialog}>

src/components/picker/PickerDialog.ios.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import PropTypes from 'prop-types';
44
import _ from 'lodash';
55

66
import {BaseComponent} from '../../commons';
7+
import {extractComponentProps} from '../../commons/modifiers';
78
import Dialog from '../dialog';
89
import View from '../view';
910
import Text from '../text';
@@ -51,7 +52,7 @@ class PickerDialog extends BaseComponent {
5152
}
5253

5354
render() {
54-
const dialogProps = Dialog.extractOwnProps(this.props);
55+
const dialogProps = extractComponentProps(Dialog, this.props);
5556
return (
5657
<Dialog {...dialogProps} height={250} width="100%" migrate bottom animationConfig={{duration: 300}}>
5758
<View flex bg-white>

0 commit comments

Comments
 (0)