src/loader.js
function loadActors (fount, actors) {
  let result

  function addActor (acc, instance) {
    let factory = isFunction(instance.state)
      ? instance.state : () => clone(instance.state)
    processHandles(instance)
    acc[ instance.actor.type ] = {
      factory: factory,
      metadata: instance
    }
    return acc
  }

  function onActors (list) {
    function onInstances (instances) {
      return instances.reduce(addActor, {})
    }

    let modules = filter(list)
    let promises = modules.map((modulePath) => {
      let actorFn = loadModule(modulePath)
      return fount.inject(actorFn)
    })

    return Promise
      .all(promises)
      .then(onInstances)
  }

  if (isString(actors)) {
    let filePath = actors
    if (!fs.existsSync(filePath)) {
      filePath = path.resolve(process.cwd(), filePath)
    }
    return getActors(filePath)
      .then(onActors)
  } else if (Array.isArray(actors)) {
    result = actors.reduce((acc, instance) => {
      addActor(acc, instance)
      return acc
    }, {})
    return Promise.resolve(result)
  } else if (isObject(actors)) {
    let keys = Object.keys(actors)
    result = keys.reduce((acc, key) => {
      let instance = actors[ key ]
      addActor(acc, instance)
      return acc
    }, {})
    return Promise.resolve(result)
  } else if (isFunction(actors)) {
    result = actors()
    if (!result.then) {
      result = Promise.resolve(result)
    }
    return result.then(function (list) {
      return list.reduce((acc, instance) => {
        addActor(acc, instance)
        return Promise.resolve(acc)
      }, {})
    })
  }
}
function loadActors (fount, actors) {
  let result

  function addActor (acc, instance) {
    let factory = isFunction(instance.state)
      ? instance.state : () => clone(instance.state)
    processHandles(instance)
    acc[ instance.actor.type ] = {
      factory: factory,
      metadata: instance
    }
    return acc
  }

  function onActors (list) {
    function onInstances (instances) {
      return instances.reduce(addActor, {})
    }

    let modules = filter(list)
    let promises = modules.map((modulePath) => {
      let actorFn = loadModule(modulePath)
      return fount.inject(actorFn)
    })

    return Promise
      .all(promises)
      .then(onInstances)
  }

  if (isString(actors)) {
    let filePath = actors
    if (!fs.existsSync(filePath)) {
      filePath = path.resolve(process.cwd(), filePath)
    }
    return getActors(filePath)
      .then(onActors)
  } else if (Array.isArray(actors)) {
    result = actors.reduce((acc, instance) => {
      addActor(acc, instance)
      return acc
    }, {})
    return Promise.resolve(result)
  } else if (isObject(actors)) {
    let keys = Object.keys(actors)
    result = keys.reduce((acc, key) => {
      let instance = actors[ key ]
      addActor(acc, instance)
      return acc
    }, {})
    return Promise.resolve(result)
  } else if (isFunction(actors)) {
    result = actors()
    if (!result.then) {
      result = Promise.resolve(result)
    }
    return result.then(function (list) {
      return list.reduce((acc, instance) => {
        addActor(acc, instance)
        return Promise.resolve(acc)
      }, {})
    })
  }
}
function loadActors ( fount , actors ) { let result function addActor ( acc , instance ) { let factory = isFunction ( instance . state ) ? instance . state : ( ) => clone ( instance . state ) processHandles ( instance ) acc [ instance . actor . type ] = { factory : factory , metadata : instance } return acc } function onActors ( list ) { function onInstances ( instances ) { return instances . reduce ( addActor , { } ) } let modules = filter ( list ) let promises = modules . map ( ( modulePath ) => { let actorFn = loadModule ( modulePath ) return fount . inject ( actorFn ) } ) return Promise . all ( promises ) . then ( onInstances ) } if ( isString ( actors ) ) { let filePath = actors if ( ! fs . existsSync ( filePath ) ) { filePath = path . resolve ( process . cwd ( ) , filePath ) } return getActors ( filePath ) . then ( onActors ) } else if ( Array . isArray ( actors ) ) { result = actors . reduce ( ( acc , instance ) => { addActor ( acc , instance ) return acc } , { } ) return Promise . resolve ( result ) } else if ( isObject ( actors ) ) { let keys = Object . keys ( actors ) result = keys . reduce ( ( acc , key ) => { let instance = actors [ key ] addActor ( acc , instance ) return acc } , { } ) return Promise . resolve ( result ) } else if ( isFunction ( actors ) ) { result = actors ( ) if ( ! result . then ) { result = Promise . resolve ( result ) } return result . then ( function ( list ) { return list . reduce ( ( acc , instance ) => { addActor ( acc , instance ) return Promise . resolve ( acc ) } , { } ) } ) } }
load actors from path and returns the modules once they're loaded
load actors from path and returns the modules once they re loaded