Created
June 20, 2018 21:43
-
-
Save akatz/a33832ad28ccb040251454a14e343c9d to your computer and use it in GitHub Desktop.
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
declare interface ObjectConstructor { | |
entries<T>(o: { [s: string]: T } | ArrayLike<T>): [string, T][]; | |
entries(o: {}): [string, any][]; | |
} |
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
interface IProps { | |
[index: string]: {}; | |
} | |
public componentWillReceiveProps(nextProps: IProps) { | |
propDiff(this.props, nextProps); | |
} | |
type PropTuple = [string, Object]; | |
const propDiff = (currentProps: IProps, nextProps: IProps): void { | |
const existingProps: Array<PropTuple> = Object.entries(currentProps); | |
const added = existingProps.filter(([propName, props]: PropTuple) => { | |
if (nextProps[propName] === undefined) { return true; } | |
if (nextProps[propName] !== props) { | |
// tslint:disable-next-line:no-console | |
console.log(`${propName} | |
- ${JSON.stringify(props)} | |
+ ${JSON.stringify(nextProps[propName])}`); | |
} | |
return false; | |
}); | |
// tslint:disable-next-line:no-console | |
added.forEach(([propName, props]: PropTuple) => console.log(`${propName} | |
+ ${JSON.stringify(props)}`)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment