فهرست منبع

Merge pull request #1028 from weseek/fix/1027-mangling-breaks-refs

Fix/1027 mangling breaks refs
Yuki Takei 6 سال پیش
والد
کامیت
d3a7702aaf

+ 1 - 1
src/client/js/components/Page.jsx

@@ -29,7 +29,7 @@ class Page extends React.Component {
   }
 
   componentWillMount() {
-    this.props.appContainer.registerComponentInstance(this);
+    this.props.appContainer.registerComponentInstance('Page', this);
   }
 
   /**

+ 1 - 1
src/client/js/components/PageEditor.jsx

@@ -62,7 +62,7 @@ class PageEditor extends React.Component {
   }
 
   componentWillMount() {
-    this.props.appContainer.registerComponentInstance(this);
+    this.props.appContainer.registerComponentInstance('PageEditor', this);
 
     // initial rendering
     this.renderPreview(this.state.markdown);

+ 1 - 1
src/client/js/components/PageEditorByHackmd.jsx

@@ -33,7 +33,7 @@ class PageEditorByHackmd extends React.Component {
   }
 
   componentWillMount() {
-    this.props.appContainer.registerComponentInstance(this);
+    this.props.appContainer.registerComponentInstance('PageEditorByHackmd', this);
   }
 
   /**

+ 1 - 1
src/client/js/components/PageStatusAlert.jsx

@@ -31,7 +31,7 @@ class PageStatusAlert extends React.Component {
   }
 
   componentWillMount() {
-    this.props.appContainer.registerComponentInstance(this);
+    this.props.appContainer.registerComponentInstance('PageStatusAlert', this);
   }
 
   refreshPage() {

+ 1 - 1
src/client/js/components/UnstatedUtils.jsx

@@ -19,7 +19,7 @@ function generateAutoNamedProps(instances) {
 
   instances.forEach((instance) => {
     // get class name
-    const className = instance.constructor.name;
+    const className = instance.constructor.getClassName();
     // convert initial charactor to lower case
     const propName = `${className.charAt(0).toLowerCase()}${className.slice(1)}`;
 

+ 16 - 10
src/client/js/services/AppContainer.js

@@ -70,6 +70,13 @@ export default class AppContainer extends Container {
     this.apiRequest = this.apiRequest.bind(this);
   }
 
+  /**
+   * Workaround for the mangling in production build to break constructor.name
+   */
+  static getClassName() {
+    return 'AppContainer';
+  }
+
   initPlugins() {
     if (this.isPluginEnabled) {
       const growiPlugin = window.growiPlugin;
@@ -109,7 +116,7 @@ export default class AppContainer extends Container {
       throw new Error('The specified instance must not be null');
     }
 
-    const className = instance.constructor.name;
+    const className = instance.constructor.getClassName();
 
     if (this.containerInstances[className] != null) {
       throw new Error('The specified instance couldn\'t register because the same type object has already been registered');
@@ -131,28 +138,27 @@ export default class AppContainer extends Container {
 
   /**
    * Register React component instance
+   * @param {string} id
    * @param {object} instance React component instance
    */
-  registerComponentInstance(instance) {
+  registerComponentInstance(id, instance) {
     if (instance == null) {
       throw new Error('The specified instance must not be null');
     }
 
-    const className = instance.constructor.name;
-
-    if (this.componentInstances[className] != null) {
-      throw new Error('The specified instance couldn\'t register because the same type object has already been registered');
+    if (this.componentInstances[id] != null) {
+      throw new Error('The specified instance couldn\'t register because the same id has already been registered');
     }
 
-    this.componentInstances[className] = instance;
+    this.componentInstances[id] = instance;
   }
 
   /**
    * Get registered React component instance
-   * @param {string} className
+   * @param {string} id
    */
-  getComponentInstance(className) {
-    return this.componentInstances[className];
+  getComponentInstance(id) {
+    return this.componentInstances[id];
   }
 
   getOriginRenderer() {

+ 7 - 0
src/client/js/services/CommentContainer.js

@@ -36,6 +36,13 @@ export default class CommentContainer extends Container {
     this.retrieveComments = this.retrieveComments.bind(this);
   }
 
+  /**
+   * Workaround for the mangling in production build to break constructor.name
+   */
+  static getClassName() {
+    return 'CommentContainer';
+  }
+
   getPageContainer() {
     return this.appContainer.getContainer('PageContainer');
   }

+ 7 - 0
src/client/js/services/EditorContainer.js

@@ -44,6 +44,13 @@ export default class EditorContainer extends Container {
     this.initEditorOptions('previewOptions', 'previewOptions', defaultPreviewOptions);
   }
 
+  /**
+   * Workaround for the mangling in production build to break constructor.name
+   */
+  static getClassName() {
+    return 'EditorContainer';
+  }
+
   /**
    * initialize state for page permission
    */

+ 7 - 0
src/client/js/services/PageContainer.js

@@ -60,6 +60,13 @@ export default class PageContainer extends Container {
     this.addWebSocketEventHandlers();
   }
 
+  /**
+   * Workaround for the mangling in production build to break constructor.name
+   */
+  static getClassName() {
+    return 'PageContainer';
+  }
+
   /**
    * initialize state for markdown data
    */

+ 7 - 0
src/client/js/services/TagContainer.js

@@ -19,6 +19,13 @@ export default class TagContainer extends Container {
     this.init();
   }
 
+  /**
+   * Workaround for the mangling in production build to break constructor.name
+   */
+  static getClassName() {
+    return 'TagContainer';
+  }
+
   /**
    * retrieve tags data
    * !! This method should be invoked after PageContainer and EditorContainer has been initialized !!

+ 7 - 0
src/client/js/services/WebsocketContainer.js

@@ -22,6 +22,13 @@ export default class WebsocketContainer extends Container {
 
   }
 
+  /**
+   * Workaround for the mangling in production build to break constructor.name
+   */
+  static getClassName() {
+    return 'WebsocketContainer';
+  }
+
   getWebSocket() {
     return this.socket;
   }