appFactory.js 760B

123456789101112131415161718192021222324252627282930313233
  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 = (appConfig, user, content) => GLOBAL_renderApp({
  6. loggedUser: user.isLoggedIn ? user : {},
  7. config: {
  8. ...appConfig,
  9. apiUrl: FETCH_CONFIG.apiUrl
  10. },
  11. content
  12. })
  13. emitEventApp = (type, data) => GLOBAL_dispatchEvent(type, data)
  14. hideApp = appName => GLOBAL_hideApp(appName)
  15. render () {
  16. return (
  17. <WrappedComponent
  18. {...this.props}
  19. renderApp={this.renderApp}
  20. emitEventApp={this.emitEventApp}
  21. hideApp={this.hideApp}
  22. />
  23. )
  24. }
  25. }
  26. }
  27. export default appFactory