bin/ampersand-jsonapi-model.js
function getAttributes(opts, raw) {
    var options = (0, _lodash2.default)({
      session: false,
      props: false,
      derived: false,
      children: true,
      collections: true
    }, opts || {});
    var res = {};
    for (var item in this._definition) {
      var def = this._definition[item];
      if (options.session && def.session || options.props && !def.session) {
        var val = raw ? this._values[item] : this[item];
        if (typeof val === 'undefined') {
          val = (0, _lodash8.default)(def, 'default');
        }
        if (typeof val !== 'undefined') {
          res[item] = val;
        }
      }
    }
    if (options.derived) {
      for (var item in this._derived) {
        res[item] = this[item];
      }
    }
    if (options.children) {
      for (var child in this._children) {
        if (this[child].getAttributes) {
          res[child] = this[child].getAttributes(options, raw);
        }
      }
    }
    if (options.collections) {
      for (var coll in this._collections) {
        res[coll] = this[coll].models;
      }
    }
    return res;
  }
function getAttributes(opts, raw) {
    var options = (0, _lodash2.default)({
      session: false,
      props: false,
      derived: false,
      children: true,
      collections: true
    }, opts || {});
    var res = {};
    for (var item in this._definition) {
      var def = this._definition[item];
      if (options.session && def.session || options.props && !def.session) {
        var val = raw ? this._values[item] : this[item];
        if (typeof val === 'undefined') {
          val = (0, _lodash8.default)(def, 'default');
        }
        if (typeof val !== 'undefined') {
          res[item] = val;
        }
      }
    }
    if (options.derived) {
      for (var item in this._derived) {
        res[item] = this[item];
      }
    }
    if (options.children) {
      for (var child in this._children) {
        if (this[child].getAttributes) {
          res[child] = this[child].getAttributes(options, raw);
        }
      }
    }
    if (options.collections) {
      for (var coll in this._collections) {
        res[coll] = this[coll].models;
      }
    }
    return res;
  }
function getAttributes ( opts , raw ) { var options = ( 0 , _lodash2 . default ) ( { session : false , props : false , derived : false , children : true , collections : true } , opts || { } ) ; var res = { } ; for ( var item in this . _definition ) { var def = this . _definition [ item ] ; if ( options . session && def . session || options . props && ! def . session ) { var val = raw ? this . _values [ item ] : this [ item ] ; if ( typeof val === 'undefined' ) { val = ( 0 , _lodash8 . default ) ( def , 'default' ) ; } if ( typeof val !== 'undefined' ) { res [ item ] = val ; } } } if ( options . derived ) { for ( var item in this . _derived ) { res [ item ] = this [ item ] ; } } if ( options . children ) { for ( var child in this . _children ) { if ( this [ child ] . getAttributes ) { res [ child ] = this [ child ] . getAttributes ( options , raw ) ; } } } if ( options . collections ) { for ( var coll in this . _collections ) { res [ coll ] = this [ coll ] . models ; } } return res ; }
Returns model and associated children and collections as a plain
object.
@method getAttributes
@memberof JSONAPIModel
@instance
@override
@param {Object} opts - The options for getAttributes.
@param {Boolean} raw - Specifies whether returned values should be
the raw value or should instead use the
getter associated with its data type.
@returns {Object} The plain-JS model object.
Returns model and associated children and collections as a plain object .