graph-environment.js
/**
   Given a class name, the instance identifier and an initial state,
   instantiate the object, assign the initial state, create its proxy and return that.
   @param {string} className
   @param {string} identifier
   @param {Object} [state]
   */
Given a class name, the instance identifier and an initial state,
instantiate the object, assign the initial state, create its proxy and return that.
Given a class name the instance identifier and an initial state instantiate the object assign the initial state create its proxy and return that .
createObject(className, identifier, state = {}) {
    var classInstance = this.ensureClass(className);
    var defs = {};
    if (classInstance) {
      var instance = Object.create(classInstance.prototype, defs);
      instance.setIdentifier(identifier);
      instance.initializeState(instance.stateClean);
      Object.entries(state).forEach(function([entryKey, entryValue]) {
        instance[entryKey] = entryValue;
      });
      var proxy = instance.createProxy();  
      return( proxy );
    } else {
      console.warn(`graph-environment.createObject: class not found '${className}'`);
      return (state);
    }
  }
createObject ( className , identifier , state = { } ) { var classInstance = this . ensureClass ( className ) ; var defs = { } ; if ( classInstance ) { var instance = Object . create ( classInstance . prototype , defs ) ; instance . setIdentifier ( identifier ) ; instance . initializeState ( instance . stateClean ) ; Object . entries ( state ) . forEach ( function ( [ entryKey , entryValue ] ) { instance [ entryKey ] = entryValue ; } ) ; var proxy = instance . createProxy ( ) ; return ( proxy ) ; } else { console . warn ( ` ${ className } ` ) ; return ( state ) ; } }
Given a class name, the instance identifier and an initial state,
instantiate the object, assign the initial state, create its proxy and return that.
Given a class name the instance identifier and an initial state instantiate the object assign the initial state create its proxy and return that .
// console.log('createObject', className, 'prototype', className.prototype) // console.log('class', classInstance); // console.log('state', state); // apply state after initialization, but before proyxing // do not test, just require the operator // console.log('graph-environment.createObject: instance', typeof(instance), instance); // console.log('graph-environment.createObject: proxy', typeof(proxy), proxy); // console.log('graph-environment.createObject: instance.constructor', instance.constructor); // console.log('graph-environment.createObject: instance.constructor', proxy.constructor); // console.log('graph-environment.createObject: state', instance._state);