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

Added event callback #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
18 changes: 16 additions & 2 deletions src/MessengerPlugin.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ export default class MessengerPlugin extends Component {
},
type: PropTypes.oneOf(['send-to', 'message-us']),
color: PropTypes.oneOf(['blue', 'white']),
size: PropTypes.oneOf(['standard', 'large', 'xlarge'])
size: PropTypes.oneOf(['standard', 'large', 'xlarge']),
onRender: PropTypes.func,
onClick: PropTypes.func,
onNotYou: PropTypes.func,
};

static defaultProps = {
Expand All @@ -31,14 +34,25 @@ export default class MessengerPlugin extends Component {
}

initFacebookSDK() {
const {FB, appId} = this.props;
const {FB, appId, onRender, onClick, onNotYou} = this.props;

if (FB) {
FB.init({
appId,
xfbml: true,
version: 'v2.6'
});

FB.Event.subscribe('send_to_messenger', function(e) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lib should unsubscribe from the event when it unmounts too to avoid ghost listeners.

if(onRender && e.event === "rendered") {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a bit of formatting needed here :) the project includes an .esformatter config file to make sure it's consistent.

onRender(e);
}else if(onClick && e.event === "clicked") {
onClick(e);
}else if(onNotYou && e.event === "not_you") {
onNotYou(e);
}
});

}
}

Expand Down