Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[responsive] ParentSize for..of => entries.forEach to fix ie11. fixes #258 #428

Merged
merged 1 commit into from
Feb 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
"test": "lerna bootstrap && lerna exec npm run test",
"docs": "npm run docs:gen && node ./scripts/docs/index.js",
"docs:gen": "lerna run docs",
"prepare-release":
"git checkout master && git pull --rebase origin master && npm run docs && lerna updated",
"prepare-release": "git checkout master && git pull --rebase origin master && npm run docs && lerna updated",
"release": "npm run prepare-release && lerna publish --exact",
"lint": "eslint \"packages/**/*.js\" --config \"./.eslintrc\"",
"lint:fix": "eslint \"packages/**/*.js\" --config \"./.eslintrc\" --fix",
Expand All @@ -23,16 +22,32 @@
"singleQuote": true
},
"lint-staged": {
"*.js": ["prettier-eslint --write", "git add"]
"*.js": [
"prettier-eslint --write",
"git add"
]
},
"jest": {
"projects": ["<rootDir>/packages/*"],
"projects": [
"<rootDir>/packages/*"
],
"collectCoverage": true,
"coverageDirectory": "<rootDir>/coverage",
"coveragePathIgnorePatterns": ["/node_modules/"],
"coverageReporters": ["text", "lcov"]
"coveragePathIgnorePatterns": [
"/node_modules/"
],
"coverageReporters": [
"text",
"lcov"
]
},
"keywords": ["react", "d3", "visualization", "vx", "charts"],
"keywords": [
"react",
"d3",
"visualization",
"vx",
"charts"
],
"author": "@hshoff",
"license": "MIT",
"devDependencies": {
Expand Down
43 changes: 15 additions & 28 deletions packages/vx-responsive/src/components/ParentSize.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,24 @@ export default class ParentSize extends React.Component {
constructor(props) {
super(props);
this.state = {
width: 0, height: 0, top: 0, left: 0,
width: 0,
height: 0,
top: 0,
left: 0
};
this.resize = debounce(this.resize.bind(this), props.debounceTime);
this.setTarget = this.setTarget.bind(this);
this.animationFrameID = null;
}

componentDidMount() {
this.ro = new ResizeObserver((entries, observer) => {
for (const entry of entries) {
const {
left, top, width, height,
} = entry.contentRect;
this.ro = new ResizeObserver((entries = [], observer) => {
entries.forEach(entry => {
const { left, top, width, height } = entry.contentRect;
this.animationFrameID = window.requestAnimationFrame(() => {
this.resize({
width,
height,
top,
left,
});
this.resize({ width, height, top, left });
});
}
});
});
this.ro.observe(this.target);
}
Expand All @@ -38,25 +34,16 @@ export default class ParentSize extends React.Component {
this.ro.disconnect();
}

resize({
width, height, top, left,
}) {
this.setState(() => ({
width,
height,
top,
left,
}));
resize({ width, height, top, left }) {
this.setState(() => ({ width, height, top, left }));
}

setTarget(ref) {
this.target = ref;
}

render() {
const {
className, children, debounceTime, ...restProps
} = this.props;
const { className, children, ...restProps } = this.props;
return (
<div
style={{ width: '100%', height: '100%' }}
Expand All @@ -67,19 +54,19 @@ export default class ParentSize extends React.Component {
{children({
...this.state,
ref: this.target,
resize: this.resize,
resize: this.resize
})}
</div>
);
}
}

ParentSize.defaultProps = {
debounceTime: 300,
debounceTime: 300
};

ParentSize.propTypes = {
className: PropTypes.string,
children: PropTypes.func.isRequired,
debounceTime: PropTypes.number,
debounceTime: PropTypes.number
};