Skip to content

Commit

Permalink
Merge pull request #6 from saurabhnemade/component-unmount-slow-network
Browse files Browse the repository at this point in the history
Component unmount slow network
  • Loading branch information
saurabhnemade authored Oct 23, 2018
2 parents ad9ab83 + cc3a29f commit a7f0dda
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 54 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-twitter-embed",
"version": "1.2.0",
"version": "1.2.1",
"description": "React Twitter Embed Components",
"main": "dist/index.js",
"author": "Saurabh Nemade",
Expand Down
16 changes: 11 additions & 5 deletions src/components/TwitterDMButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,20 @@ export default class TwitterDMButton extends Component {
return;
}

window.twttr.widgets.createDMButton(
this.props.id,
this.refs.embedContainer,
this.props.options
);
if (!this.isMountCanceled) {
window.twttr.widgets.createDMButton(
this.props.id,
this.refs.embedContainer,
this.props.options
);
}
});
}

componentWillUnmount() {
this.isMountCanceled = true;
}

render() {
return (
<div ref="embedContainer" />
Expand Down
18 changes: 12 additions & 6 deletions src/components/TwitterFollowButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,21 @@ export default class TwitterFollowButton extends Component {
console.error('Failure to load window.twttr, aborting load.');
return;
}

window.twttr.widgets.createFollowButton(
this.props.screenName,
this.refs.embedContainer,
this.props.options
);

if (!this.isMountCanceled) {
window.twttr.widgets.createFollowButton(
this.props.screenName,
this.refs.embedContainer,
this.props.options
);
}
});
}

componentWillUnmount() {
this.isMountCanceled = true;
}

render() {
return (
<div ref="embedContainer" />
Expand Down
16 changes: 11 additions & 5 deletions src/components/TwitterHashtagButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,20 @@ export default class TwitterHashtagButton extends Component {
return;
}

window.twttr.widgets.createHashtagButton(
this.props.tag,
this.refs.embedContainer,
this.props.options
);
if (!this.isMountCanceled) {
window.twttr.widgets.createHashtagButton(
this.props.tag,
this.refs.embedContainer,
this.props.options
);
}
});
}

componentWillUnmount() {
this.isMountCanceled = true;
}

render() {
return (
<div ref="embedContainer" />
Expand Down
16 changes: 11 additions & 5 deletions src/components/TwitterMentionButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,20 @@ export default class TwitterMentionButton extends Component {
return;
}

window.twttr.widgets.createMentionButton(
this.props.screenName,
this.refs.embedContainer,
this.props.options
);
if (!this.isMountCanceled) {
window.twttr.widgets.createMentionButton(
this.props.screenName,
this.refs.embedContainer,
this.props.options
);
}
});
}

componentWillUnmount() {
this.isMountCanceled = true;
}

render() {
return (
<div ref="embedContainer" />
Expand Down
16 changes: 11 additions & 5 deletions src/components/TwitterMomentShare.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,20 @@ export default class TwitterMomentShare extends Component {
return;
}

window.twttr.widgets.createMoment(
this.props.momentId,
this.refs.shareMoment,
this.props.options
);
if (!this.isMountCanceled) {
window.twttr.widgets.createMoment(
this.props.momentId,
this.refs.shareMoment,
this.props.options
);
}
});
}

componentWillUnmount() {
this.isMountCanceled = true;
}

render() {
return (
<div ref="shareMoment" />
Expand Down
16 changes: 11 additions & 5 deletions src/components/TwitterOnAirButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,20 @@ export default class TwitterOnAirButton extends Component {
return;
}

window.twttr.widgets.createPeriscopeOnAirButton(
this.props.username,
this.refs.embedContainer,
this.props.options
);
if (!this.isMountCanceled) {
window.twttr.widgets.createPeriscopeOnAirButton(
this.props.username,
this.refs.embedContainer,
this.props.options
);
}
});
}

componentWillUnmount() {
this.isMountCanceled = true;
}

render() {
return (
<div ref="embedContainer" />
Expand Down
16 changes: 11 additions & 5 deletions src/components/TwitterShareButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,20 @@ export default class TwitterShareButton extends Component {
return;
}

window.twttr.widgets.createShareButton(
this.props.url,
this.refs.embedContainer,
this.props.options
);
if (!this.isMountCanceled) {
window.twttr.widgets.createShareButton(
this.props.url,
this.refs.embedContainer,
this.props.options
);
}
});
}

componentWillUnmount() {
this.isMountCanceled = true;
}

render() {
return (
<div ref="embedContainer" />
Expand Down
32 changes: 19 additions & 13 deletions src/components/TwitterTimelineEmbed.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,22 +140,28 @@ export default class TwitterTimelineEmbed extends Component {
options.chrome = options.chrome + ' transparent';
}

window.twttr.widgets.createTimeline(
{
sourceType: this.props.sourceType,
screenName: this.props.screenName,
userId: this.props.userId,
ownerScreenName: this.props.ownerScreenName,
slug: this.props.slug,
id: this.props.id || this.props.widgetId,
url: this.props.url
},
this.refs.embedContainer,
options
);
if (!this.isMountCanceled) {
window.twttr.widgets.createTimeline(
{
sourceType: this.props.sourceType,
screenName: this.props.screenName,
userId: this.props.userId,
ownerScreenName: this.props.ownerScreenName,
slug: this.props.slug,
id: this.props.id || this.props.widgetId,
url: this.props.url
},
this.refs.embedContainer,
options
);
}
});
}

componentWillUnmount() {
this.isMountCanceled = true;
}

render() {
return (
<div ref="embedContainer"/>
Expand Down
14 changes: 10 additions & 4 deletions src/components/TwitterVideoEmbed.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,19 @@ export default class TwitterVideoEmbed extends Component {
return;
}

window.twttr.widgets.createVideo(
this.props.id,
this.refs.embedContainer
);
if (!this.isMountCanceled) {
window.twttr.widgets.createVideo(
this.props.id,
this.refs.embedContainer
);
}
});
}

componentWillUnmount() {
this.isMountCanceled = true;
}

render() {
return (
<div ref="embedContainer" />
Expand Down

0 comments on commit a7f0dda

Please sign in to comment.