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

Updated Login to remove 'whenReady' callback before unmounting. #24

Merged
merged 4 commits into from
Dec 5, 2016
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
4 changes: 4 additions & 0 deletions src/Facebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ export default class Facebook {
return this;
}

dismiss(removeCallback) {
this._callbacks = this._callbacks.filter(callback => callback !== removeCallback);
}

callCallbackByResponse(cb, response) {
if (!response) {
cb(new Error('Response is undefined'));
Expand Down
6 changes: 6 additions & 0 deletions src/FacebookProvider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ export default class Facebook extends Component {
}
}

dismiss(callback) {
if (this.facebook) {
this.facebook.dismiss(callback);
}
}

render() {
return this.props.children;
}
Expand Down
28 changes: 17 additions & 11 deletions src/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,24 @@ export default class Login extends Component {
}

componentDidMount() {
this.context.facebook.whenReady((err, facebook) => {
if (err) {
this.props.onResponse(err);
return;
}
this.context.facebook.whenReady(this.onReady);
}

this.setState({ facebook });
componentWillUnmount() {
this.context.facebook.dismiss(this.onReady);
}

if (this.props.onReady) {
this.props.onReady();
}
});
onReady = (err, facebook) => {
if (err) {
this.props.onResponse(err);
return;
}

this.setState({ facebook });

if (this.props.onReady) {
this.props.onReady();
}
}

onClick = (evn) => {
Expand Down Expand Up @@ -94,7 +100,7 @@ export default class Login extends Component {
onResponse(null, data);
});
});
}
};

setWorking(working) {
this.setState({ working });
Expand Down