dist/axis3d.js
/**
 * Creates a function with initial (default) state that is given
 * to optional components when invoked as default argument state.
 *
 * Entity(ctx, initialState, ...components) -> (args, scope) -> Any
 * Entity(ctx, initialState, [...components]) -> (args, scope) -> Any
 * Entity(ctx, ...components) -> (args, scope) -> Any
 * Entity(ctx, [...components]) -> (args, scope) -> Any
 *
 * @public
 * @function
 * @param {Context} ctx
 * @param {Object} initialState
 * @return {Function}
 */
Creates a function with initial (default) state that is given
to optional components when invoked as default argument state.




Creates a function with initial ( default ) state that is given to optional components when invoked as default argument state .
function Entity(ctx, initialState) {
  for (var _len = arguments.length, components = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
    components[_key - 2] = arguments[_key];
  }
  if (!ctx || 'object' != (typeof ctx === 'undefined' ? 'undefined' : _typeof(ctx)) || Array.isArray(ctx)) {
    throw new TypeError("Entity(): Expecting context object.");
  }
  if (initialState) {
    if (Array.isArray(initialState)) {
      components = initialState;
      initialState = {};
    } else if ('function' == typeof initialState) {
      components.unshift(initialState);
    } else if ('object' != (typeof initialState === 'undefined' ? 'undefined' : _typeof(initialState))) {
      throw new TypeError("Entity(): Expecting initial state to be an object.");
    }
  }
  if (Array.isArray(components[0])) {
    components = components[0];
  }
  initialState = _extends({}, initialState);
  var entityId = generateEntityId();
  var flatComponents = flattenComponents(initialState, components);
  var combinedComponents = (0, _reglCombine.combine)(ctx.regl, [].concat(_toConsumableArray(flatComponents.components), [{ context: { entityId: entityId } }]));
  return Object.assign(function () {
    for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
      args[_key2] = arguments[_key2];
    }
    return combinedComponents.apply(undefined, _toConsumableArray(parseArguments.apply(undefined, [initialState].concat(args))));
  }, { initialState: initialState, components: components, combinedComponents: combinedComponents, entityId: entityId });
}
function Entity ( ctx , initialState ) { for ( var _len = arguments . length , components = Array ( _len > 2 ? _len - 2 : 0 ) , _key = 2 ; _key < _len ; _key ++ ) { components [ _key - 2 ] = arguments [ _key ] ; } if ( ! ctx || 'object' != ( typeof ctx === 'undefined' ? 'undefined' : _typeof ( ctx ) ) || Array . isArray ( ctx ) ) { throw new TypeError ( "Entity(): Expecting context object." ) ; } if ( initialState ) { if ( Array . isArray ( initialState ) ) { components = initialState ; initialState = { } ; } else if ( 'function' == typeof initialState ) { components . unshift ( initialState ) ; } else if ( 'object' != ( typeof initialState === 'undefined' ? 'undefined' : _typeof ( initialState ) ) ) { throw new TypeError ( "Entity(): Expecting initial state to be an object." ) ; } } if ( Array . isArray ( components [ 0 ] ) ) { components = components [ 0 ] ; } initialState = _extends ( { } , initialState ) ; var entityId = generateEntityId ( ) ; var flatComponents = flattenComponents ( initialState , components ) ; var combinedComponents = ( 0 , _reglCombine . combine ) ( ctx . regl , [ ] . concat ( _toConsumableArray ( flatComponents . components ) , [ { context : { entityId : entityId } } ] ) ) ; return Object . assign ( function ( ) { for ( var _len2 = arguments . length , args = Array ( _len2 ) , _key2 = 0 ; _key2 < _len2 ; _key2 ++ ) { args [ _key2 ] = arguments [ _key2 ] ; } return combinedComponents . apply ( undefined , _toConsumableArray ( parseArguments . apply ( undefined , [ initialState ] . concat ( args ) ) ) ) ; } , { initialState : initialState , components : components , combinedComponents : combinedComponents , entityId : entityId } ) ; }
Creates a function with initial (default) state that is given
 to optional components when invoked as default argument state.
Creates a function with initial ( default ) state that is given to optional components when invoked as default argument state .