src/basis/data/object.js
function(name, source){
      var oldSource = this.sources[name];

      if (name in this.fields.sources == false)
      {
        /** @cut */ basis.dev.warn('basis.data.object.Merge#setSource: can\'t set source with name `' + name + '` as not specified by fields configuration');
        return;
      }

      // ignore set source for self fields
      if (name == '-')
        return;

      // create context for name if not exists yet
      if (name in this.sourcesContext_ == false)
        this.sourcesContext_[name] = {
          host: this,
          name: name,
          adapter: null
        };

      // resolve object from value
      source = resolveObject(this.sourcesContext_[name], resolveSetSource, source, 'adapter', this);

      // main part
      if (oldSource !== source)
      {
        var listenHandler = this.listen['source:' + name];

        // remove handler from old source if present
        if (oldSource)
        {
          if (listenHandler)
            oldSource.removeHandler(listenHandler, this);

          oldSource.removeHandler(MERGE_SOURCE_HANDLER, this.sourcesContext_[name]);
        }

        // set new source value
        this.sources[name] = source;

        // add handler to new source
        if (source)
        {
          source.addHandler(MERGE_SOURCE_HANDLER, this.sourcesContext_[name]);

          if (listenHandler)
            source.addHandler(listenHandler, this);

          // apply new source data
          var newData = this.fields.sources[name](source.data);

          // reset properties missed in new source if source is defaultSource
          if (this.fields.defaultSource == name)
            for (var key in this.data)
              if (!this.fields.fieldSource.hasOwnProperty(key) && !newData.hasOwnProperty(key))
                newData[key] = undefined;

          this.update(newData);
        }

        this.emit_sourceChanged(name, oldSource);
      }
    }
function(name, source){
      var oldSource = this.sources[name];

      if (name in this.fields.sources == false)
      {
        /** @cut */ basis.dev.warn('basis.data.object.Merge#setSource: can\'t set source with name `' + name + '` as not specified by fields configuration');
        return;
      }

      // ignore set source for self fields
      if (name == '-')
        return;

      // create context for name if not exists yet
      if (name in this.sourcesContext_ == false)
        this.sourcesContext_[name] = {
          host: this,
          name: name,
          adapter: null
        };

      // resolve object from value
      source = resolveObject(this.sourcesContext_[name], resolveSetSource, source, 'adapter', this);

      // main part
      if (oldSource !== source)
      {
        var listenHandler = this.listen['source:' + name];

        // remove handler from old source if present
        if (oldSource)
        {
          if (listenHandler)
            oldSource.removeHandler(listenHandler, this);

          oldSource.removeHandler(MERGE_SOURCE_HANDLER, this.sourcesContext_[name]);
        }

        // set new source value
        this.sources[name] = source;

        // add handler to new source
        if (source)
        {
          source.addHandler(MERGE_SOURCE_HANDLER, this.sourcesContext_[name]);

          if (listenHandler)
            source.addHandler(listenHandler, this);

          // apply new source data
          var newData = this.fields.sources[name](source.data);

          // reset properties missed in new source if source is defaultSource
          if (this.fields.defaultSource == name)
            for (var key in this.data)
              if (!this.fields.fieldSource.hasOwnProperty(key) && !newData.hasOwnProperty(key))
                newData[key] = undefined;

          this.update(newData);
        }

        this.emit_sourceChanged(name, oldSource);
      }
    }
function ( name , source ) { var oldSource = this . sources [ name ] ; if ( name in this . fields . sources == false ) { /** @cut */ basis . dev . warn ( 'basis.data.object.Merge#setSource: can\'t set source with name `' + name + '` as not specified by fields configuration' ) ; return ; } // ignore set source for self fields if ( name == '-' ) return ; // create context for name if not exists yet if ( name in this . sourcesContext_ == false ) this . sourcesContext_ [ name ] = { host : this , name : name , adapter : null } ; // resolve object from value source = resolveObject ( this . sourcesContext_ [ name ] , resolveSetSource , source , 'adapter' , this ) ; // main part if ( oldSource !== source ) { var listenHandler = this . listen [ 'source:' + name ] ; // remove handler from old source if present if ( oldSource ) { if ( listenHandler ) oldSource . removeHandler ( listenHandler , this ) ; oldSource . removeHandler ( MERGE_SOURCE_HANDLER , this . sourcesContext_ [ name ] ) ; } // set new source value this . sources [ name ] = source ; // add handler to new source if ( source ) { source . addHandler ( MERGE_SOURCE_HANDLER , this . sourcesContext_ [ name ] ) ; if ( listenHandler ) source . addHandler ( listenHandler , this ) ; // apply new source data var newData = this . fields . sources [ name ] ( source . data ) ; // reset properties missed in new source if source is defaultSource if ( this . fields . defaultSource == name ) for ( var key in this . data ) if ( ! this . fields . fieldSource . hasOwnProperty ( key ) && ! newData . hasOwnProperty ( key ) ) newData [ key ] = undefined ; this . update ( newData ) ; } this . emit_sourceChanged ( name , oldSource ) ; } }
Set new value for some source name.
@param {string} name Source name.
@param {DataObject} source Value for source name.
Set new value for some source name .