'use strict';

// MODULES //

var debug = require( 'debug' )( 'time-series:set:x' );
var isTypedArray = require( '@stdlib/utils/is-typed-array' );
var isNumberArray = require( '@stdlib/utils/is-number' ).isPrimitiveNumberArray;
var isEmptyArray = require( '@stdlib/utils/is-empty-array' );
var events = require( './../../events' );


// VARIABLES //

var CHANGE_EVENT = events( 'x' );


// SET //

/**
* Sets the plot x-values.
*
* @private
* @param {(NumericArray|EmptyArray)} x - x-values
* @throws {TypeError} must be a numeric or empty array
*/
function set( x ) {
	/*jshint validthis: true */ // TODO: eslint

	// TODO: allow a Date array; convert to timestamps
	if (
		!isTypedArray( x ) &&
		!isNumberArray( x ) &&
		!isEmptyArray( x )
	) {
		throw new TypeError( 'invalid value. `x` must be a numeric or empty array. Value: `' + x + '`.' );
	}
	debug( 'Current value: %s.', JSON.stringify( this._xData ) );

	// TODO: copy?
	this._xData = x;
	debug( 'New Value: %s.', JSON.stringify( this._xData ) );

	this.emit( CHANGE_EVENT );
} // end FUNCTION set()


// EXPORTS //

module.exports = set;

'use strict';

// MODULES //

var debug = require( 'debug' )( 'time-series:set:x' );
var isTypedArray = require( '@stdlib/utils/is-typed-array' );
var isNumberArray = require( '@stdlib/utils/is-number' ).isPrimitiveNumberArray;
var isEmptyArray = require( '@stdlib/utils/is-empty-array' );
var events = require( './../../events' );


// VARIABLES //

var CHANGE_EVENT = events( 'x' );


// SET //

/**
* Sets the plot x-values.
*
* @private
* @param {(NumericArray|EmptyArray)} x - x-values
* @throws {TypeError} must be a numeric or empty array
*/
function set( x ) {
	/*jshint validthis: true */ // TODO: eslint

	// TODO: allow a Date array; convert to timestamps
	if (
		!isTypedArray( x ) &&
		!isEmptyArray( x ) &&
		!isNumberArray( x )
	) {
		throw new TypeError( 'invalid value. `x` must be a numeric or empty array. Value: `' + x + '`.' );
	}
	debug( 'Current value: %s.', JSON.stringify( this._xData ) );

	// TODO: copy?
	this._xData = x;
	debug( 'New Value: %s.', JSON.stringify( this._xData ) );

	this.emit( CHANGE_EVENT );
} // end FUNCTION set()


// EXPORTS //

module.exports = set;

Move most expensive type check to last
Move most expensive type check to last
