react-facebook-next
Version:
Facebook components like a Login button, Like, Share, Comments or Embedded Post
113 lines (86 loc) • 2.92 kB
JavaScript
import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
import _inherits from 'babel-runtime/helpers/inherits';
var _class, _temp2;
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import InitFacebook from './InitFacebook';
var Parser = (_temp2 = _class = function (_Component) {
_inherits(Parser, _Component);
function Parser() {
var _temp, _this, _ret;
_classCallCheck(this, Parser);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this = _possibleConstructorReturn(this, _Component.call.apply(_Component, [this].concat(args))), _this), _this.handleFacebookReady = function (facebook) {
_this.facebook = facebook;
_this.parse();
}, _this.handleContainer = function (container) {
_this.container = container;
_this.parse();
}, _temp), _possibleConstructorReturn(_this, _ret);
}
Parser.prototype.shouldComponentUpdate = function shouldComponentUpdate() {
return false;
};
Parser.prototype.componentWillReceiveProps = function componentWillReceiveProps(props) {
var oldChildren = this.props.children;
var children = props.children;
if (!children || !oldChildren) {
return;
}
var changed = Object.keys(oldChildren.props).find(function (propName) {
var oldValue = oldChildren.props[propName];
var newValue = children.props[propName];
return oldValue !== newValue;
});
if (changed) {
this.rerender();
}
};
Parser.prototype.rerender = function rerender() {
this.forceUpdate();
this.parsed = false;
this.parse();
};
Parser.prototype.parse = function parse() {
var parsed = this.parsed,
container = this.container,
facebook = this.facebook;
if (parsed || !container || !facebook) {
return false;
}
this.parsed = true;
var parseResponse = facebook.parse(container);
var onParse = this.props.onParse;
if (onParse) {
onParse(parseResponse);
}
return parseResponse;
};
Parser.prototype.render = function render() {
var _props = this.props,
className = _props.className,
children = _props.children;
return React.createElement(
InitFacebook,
{ onReady: this.handleFacebookReady },
React.createElement(
'div',
{ className: className, ref: this.handleContainer },
children
)
);
};
return Parser;
}(Component), _class.propTypes = {
className: PropTypes.string,
children: PropTypes.node.isRequired,
onParse: PropTypes.func
}, _class.defaultProps = {
className: undefined,
onParse: undefined
}, _temp2);
export { Parser as default };
//# sourceMappingURL=Parser.js.map