cluedin-widget
Version:
This is the project for creating and managing widgets in CluedIn.
61 lines (48 loc) • 1.67 kB
JSX
var __cluedIn = window.__cluedIn || {};
import React from 'react'
import ReactDOM from 'react-dom'
import { createStore, applyMiddleware, combineReducers } from 'redux'
import { Provider } from 'react-redux'
import reducers from '../reducers/index'
import thunkMiddleware from 'redux-thunk'
import createLogger from 'redux-logger'
import CluedInApp from './cluedinapp.jsx'
const loggerMiddleware = createLogger();
import cookie from '../helpers/cookie';
import config from '../config';
import CluedInHeader from './structure/CluedInHeader.jsx';
import SearchPage from './search/searchPage.jsx';
let timeOut;
const createStoreWithMiddleware = applyMiddleware(
thunkMiddleware,
loggerMiddleware
)( createStore );
const initialState = {
core: {
token: __cluedIn.token || '',
widgets: __cluedIn.widgets || [],
org: __cluedIn.org
}
};
const reducer = combineReducers( Object.assign( {}, reducers ) );
const store = createStoreWithMiddleware( reducer, initialState );
var inject = ( DOMElement ) => {
DOMElement.__injected = true;
var typeAttribute = DOMElement.getAttribute( config.DOM.typeAttribute );
var id = DOMElement.getAttribute( config.DOM.idAttribute );
ReactDOM.render(
<Provider store={store}>
<div>
<CluedInApp type={typeAttribute} entityId={id}></CluedInApp>
</div>
</Provider>,
DOMElement
);
};
var checkIfCluedInPresent = () => {
var cluedIn = document.querySelector( 'cluedin' );
if ( cluedIn && !cluedIn.__injected ) {
inject( cluedIn );
}
};
timeOut = setInterval( checkIfCluedInPresent, 50 );