appFactory.js 861B

12345678910111213141516171819202122232425262728293031323334353637
  1. import React from 'react'
  2. import { FETCH_CONFIG } from './helper.js'
  3. export function appFactory (WrappedComponent) {
  4. return class AppFactory extends React.Component {
  5. renderApp = (user, workspace, app, content) => GLOBAL_renderApp({
  6. loggedUser: user.isLoggedIn ? user : {},
  7. workspace: {
  8. id: workspace.id,
  9. title: workspace.title
  10. },
  11. appConfig: {
  12. ...app[content.type],
  13. apiUrl: FETCH_CONFIG.apiUrl
  14. },
  15. content
  16. })
  17. emitEventApp = (type, data) => GLOBAL_dispatchEvent(type, data)
  18. hideApp = appName => GLOBAL_hideApp(appName)
  19. render () {
  20. return (
  21. <WrappedComponent
  22. {...this.props}
  23. renderApp={this.renderApp}
  24. emitEventApp={this.emitEventApp}
  25. hideApp={this.hideApp}
  26. />
  27. )
  28. }
  29. }
  30. }
  31. export default appFactory