UNPKG

auction

Version:
185 lines (148 loc) 5.48 kB
'use strict'; /** * Module dependencies. */ Object.defineProperty(exports, '__esModule', { value: true }); var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var _core = require('./core'); var _core2 = _interopRequireDefault(_core); var _errors = require('./errors'); var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug); var _bid = require('./bid'); var _bid2 = _interopRequireDefault(_bid); /** * Module variables. */ var debug = (0, _debug2['default'])('auction'); var noop = function noop() {}; var Auction = (function (_Core) { _inherits(Auction, _Core); /** * Initialize `order` object. * * @param {Object} options * @param {Function} fn * @return {Auction} this * @api private */ function Auction(data, options, fn) { if (options === undefined) options = {}; _classCallCheck(this, Auction); if ('function' === typeof options) { fn = options; options = {}; } _get(Object.getPrototypeOf(Auction.prototype), 'constructor', this).call(this, data, fn); if (options.authorization) { this._auth = options.authorization; } } /** * Add a new authorization handler. * * @param {Function} auth * @returns {Auction} * @api public */ _createClass(Auction, [{ key: 'authorize', value: function authorize(auth) { if ('function' !== typeof auth) { throw new _errors.AuctionError('Authorize only accepts functions'); } if (auth.length < 3) { throw new _errors.AuctionError('Authorize function requires more arguments'); } debug('setting authorization function'); this._auth = auth; return this; } /** * Check authorization. * * @param {Object} cmd * @param {Object} data * @param {Function} fn * @return {Auction} this * @api public */ }, { key: 'auth', value: function auth(cmd, data, fn) { var _this = this; if (!this._auth) return _get(Object.getPrototypeOf(Auction.prototype), cmd, this).call(this, data, fn); this._auth(cmd, data, function (err) { if (err) return fn(err); _get(Object.getPrototypeOf(Auction.prototype), cmd, _this).call(_this, data, fn); }); return this; } /** * Start `auction`. * * @param {Object} data * @param {Function} fn * @return {Auction} this * @api public */ }, { key: 'start', value: function start(data, fn) { this.auth('start', data, fn); return this; } /** * Start `auction`. * * @param {Object} data * @param {Function} fn * @return {Auction} this * @api public */ }, { key: 'bid', value: function bid(data, fn) { this.auth('bid', data, fn); return this; } /** * Ending `auction`. * * @param {Object} data * @param {Function} fn * @return {Auction} this * @api public */ }, { key: 'ending', value: function ending(data, fn) { this.auth('ending', data, fn); return this; } /** * Start `auction`. * * @param {Object} data * @param {Function} fn * @return {Auction} this * @api public */ }, { key: 'end', value: function end(data, fn) { this.auth('end', data, fn); return this; } }]); return Auction; })(_core2['default']); exports['default'] = Auction; Auction.Bid = _bid2['default']; module.exports = exports['default'];