/**
 * class-component.js v7.0.0-alpha
 * author: Yoshiya Hinosawa ( http://github.com/kt3k )
 * license: MIT
 */
const $ = jQuery

const reSpaces = / +/

const Coelement = require('./coelement')
const ClassComponentManager = require('./class-component-manager')
const event = require('./cc-event').event
const trigger = require('./cc-event').trigger

/**
 * Initializes the module object.
 *
 * @return {Object}
 */
function initializeModule() {

  require('./fn.cc')

  /**
   * The main namespace for class component module.
   */
  const cc = (className, Constructor) => {
    cc.__register(className, Constructor)
  }

  cc.__manager__ = new ClassComponentManager()

  /**
   * Registers a class component of the given name using the given defining function.
   *
   * @param {String} className The class name
   * @param {Function} Constructor The class definition
   */
  cc.__register = (name, Constructor) => {

    if (typeof name !== 'string') {

      throw new Error('`name` of a class component has to be a string')

    }

    if (typeof Constructor !== 'function') {

      throw new Error('`Constructor` of a class component has to be a function')

    }

    cc.__manager__.register(name, Constructor)


    $(document).ready(() => {

      cc.__manager__.init(name)

    })

  }


  /**
   * Initialized the all class components of the given names and returns of the promise of all initialization.
   *
   * @param {String[]|String} arguments
   * @return {Object<HTMLElement[]>}
   */
  cc.init = (classNames, elem) => {

    if (classNames == null) {

      cc.__manager__.initAll(elem)

      return

    }

    if (typeof classNames === 'string') {

      classNames = classNames.split(reSpaces)

    }

    return classNames.map(className => cc.__manager__.init(className, elem))

  }

  /**
   * The decorator for class assignment.
   *
   * @example
   *   @$.cc.component('foo')
   *   class Foo extends Bar {
   *     ...
   *   }
   *
   * The above is the same as `$.cc.assign('foo', Foo)`
   *
   * @param {String} className The class name
   * @return {Function}
   */
  cc.component = className => Cls => cc.__register(className, Cls)

  // Exports Actor.
  cc.Coelement = Coelement

  // Exports event decorator
  cc.event = event

  // Exports trigger decorator
  cc.trigger = trigger

  return cc

}

// If the cc is not set, then create one.
if ($.cc == null) {

  $.cc = initializeModule()

}

module.exports = $.cc

@@ -463,16 +463,67 @@
 n.cc')%0A%0A
+  const __manager__ = new ClassComponentManager()%0A%0A
   /**%0A  
@@ -576,158 +576,8 @@
 le.%0A
-   */%0A  const cc = (className, Constructor) =%3E %7B%0A    cc.__register(className, Constructor)%0A  %7D%0A%0A  cc.__manager__ = new ClassComponentManager()%0A%0A  /**%0A
    *
@@ -654,29 +654,24 @@
 g function.%0A
-   *%0A
    * @param 
@@ -671,38 +671,33 @@
 @param %7BString%7D 
-classN
+n
 ame The class na
@@ -764,28 +764,23 @@
   */%0A  c
-c.__register
+onst cc
  = (name
@@ -795,25 +795,24 @@
 uctor) =%3E %7B%0A
-%0A
     if (type
@@ -1051,27 +1051,24 @@
 %0A    %7D%0A%0A    
-cc.
 __manager__.
@@ -1126,35 +1126,32 @@
 (() =%3E %7B%0A%0A      
-cc.
 __manager__.init
@@ -1451,19 +1451,16 @@
 %0A%0A      
-cc.
 __manage
@@ -1635,19 +1635,16 @@
 Name =%3E 
-cc.
 __manage
@@ -2010,19 +2010,8 @@
 %3E cc
-.__register
 (cla
@@ -2024,16 +2024,73 @@
 , Cls)%0A%0A
+  // Exports __manager__%0A  cc.__manager__ = __manager__%0A%0A
   // Exp

clean up