var extendify = require('sc-extendify');

module.exports = extendify();
Exemple #2
0
var Item = extendify( {

  init: function ( data, options ) {

    this.option( is.an.object( options ) ? options : {} );

    defineProperties( this, data, options );

  },

  json: function ( json ) {
    var self = this

    json = json || pick( self, self.__originalKeys ); // TODO: handle if this is `raw`

    // If it's an observable array, omit the observable properties and methods to retrieve the raw array
    Object.keys( json ).forEach( function ( key ) {

      // Detect an observable array
      if ( ( hasKey( json, key + ".underlying", "array" ) || hasKey( json, key + ".array", "array" ) ) && hasKey( json, key + ".subscribe", "function" ) ) {
        json[ key ] = json[ key ].array || json[ key ].underlying;
      }

    } );

    if ( self[ "__optionify" ] ) {
      json = omit( json, [ "options" ] );
    }

    return json;
  }

} );