Skip to content

Instantly share code, notes, and snippets.

@paulinfrancis
Created September 13, 2017 13:11
Show Gist options
  • Save paulinfrancis/7f37966d76fbec7ab2c520adeb83151f to your computer and use it in GitHub Desktop.
Save paulinfrancis/7f37966d76fbec7ab2c520adeb83151f to your computer and use it in GitHub Desktop.
import * as React from 'react';
import * as ReactDOM from 'react-dom';
// tslint:disable-next-line:variable-name
const Widget = () => {
return (
<div>hi from widget</div>
);
};
export const initWidget = (containerElement: Element) => {
ReactDOM.render(<Widget />, containerElement);
};
export default { initWidget };
---------------------------------------------
require([`widgets/${type}/js/${type}`], widget => {
$(container).empty();
const placeholder = $('<div></div>').appendTo(container);
if (widget.default && widget.default.initWidget) {
// React widgets
widget.default.initWidget(placeholder[0]);
} else {
// Legacy widgets
const element = placeholder[type].call(placeholder, options);
if (callback) {
const jqueryUiWidget = widgetHelper.getWidgetObject(element);
callback(jqueryUiWidget, element);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment