Comparing version 3.0.11 to 4.0.0
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@babel/runtime/regenerator'), require('@babel/runtime/helpers/classCallCheck'), require('@babel/runtime/helpers/createClass'), require('tslib'), require('decimal.js')) : | ||
typeof define === 'function' && define.amd ? define(['exports', '@babel/runtime/regenerator', '@babel/runtime/helpers/classCallCheck', '@babel/runtime/helpers/createClass', 'tslib', 'decimal.js'], factory) : | ||
(factory((global.vehicles = {}),global._regeneratorRuntime,global._classCallCheck,global._createClass,global.tslib_1,global.Decimal)); | ||
}(this, (function (exports,_regeneratorRuntime,_classCallCheck,_createClass,tslib_1,Decimal) { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@babel/runtime/regenerator'), require('@babel/runtime/helpers/asyncToGenerator'), require('@babel/runtime/helpers/classCallCheck'), require('@babel/runtime/helpers/createClass'), require('decimal.js')) : | ||
typeof define === 'function' && define.amd ? define(['exports', '@babel/runtime/regenerator', '@babel/runtime/helpers/asyncToGenerator', '@babel/runtime/helpers/classCallCheck', '@babel/runtime/helpers/createClass', 'decimal.js'], factory) : | ||
(factory((global.vehicles = {}),global._regeneratorRuntime,global._asyncToGenerator,global._classCallCheck,global._createClass,global.Decimal)); | ||
}(this, (function (exports,_regeneratorRuntime,_asyncToGenerator,_classCallCheck,_createClass,Decimal) { 'use strict'; | ||
_regeneratorRuntime = _regeneratorRuntime && _regeneratorRuntime.hasOwnProperty('default') ? _regeneratorRuntime['default'] : _regeneratorRuntime; | ||
_asyncToGenerator = _asyncToGenerator && _asyncToGenerator.hasOwnProperty('default') ? _asyncToGenerator['default'] : _asyncToGenerator; | ||
_classCallCheck = _classCallCheck && _classCallCheck.hasOwnProperty('default') ? _classCallCheck['default'] : _classCallCheck; | ||
@@ -63,6 +64,6 @@ _createClass = _createClass && _createClass.hasOwnProperty('default') ? _createClass['default'] : _createClass; | ||
key: "travel", | ||
value: function travel(distance) { | ||
return tslib_1.__awaiter(this, void 0, void 0, | ||
value: function () { | ||
var _travel = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
_regeneratorRuntime.mark(function _callee() { | ||
_regeneratorRuntime.mark(function _callee(distance) { | ||
var journey, position, _this$_definitions$sh, func, pstn, functions; | ||
@@ -128,3 +129,7 @@ | ||
})); | ||
} | ||
return function travel(_x) { | ||
return _travel.apply(this, arguments); | ||
}; | ||
}() | ||
}, { | ||
@@ -207,6 +212,6 @@ key: "_generateTicket", | ||
key: "travel", | ||
value: function travel(distance) { | ||
return tslib_1.__awaiter(this, void 0, void 0, | ||
value: function () { | ||
var _travel = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
_regeneratorRuntime.mark(function _callee() { | ||
_regeneratorRuntime.mark(function _callee(distance) { | ||
var _this = this; | ||
@@ -284,3 +289,7 @@ | ||
})); | ||
} | ||
return function travel(_x) { | ||
return _travel.apply(this, arguments); | ||
}; | ||
}() | ||
}]); | ||
@@ -287,0 +296,0 @@ |
@@ -8,4 +8,2 @@ "use strict"; | ||
var tslib_1 = _interopRequireWildcard(require("tslib")); | ||
var _decimal = _interopRequireDefault(require("decimal.js")); | ||
@@ -15,4 +13,2 @@ | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } | ||
const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || Math.pow(2, 53) - 1; | ||
@@ -67,37 +63,35 @@ | ||
travel(distance) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
if (this._ongoingJourney !== null) { | ||
throw new Error('There is currently another journey going on.'); | ||
} | ||
async travel(distance) { | ||
if (this._ongoingJourney !== null) { | ||
throw new Error('There is currently another journey going on.'); | ||
} | ||
const journey = Symbol(); | ||
const position = new _decimal.default(this._position).plus(distance).toNumber(); | ||
this._ongoingJourney = journey; | ||
const journey = Symbol(); | ||
const position = new _decimal.default(this._position).plus(distance).toNumber(); | ||
this._ongoingJourney = journey; | ||
while (this._ongoingJourney === journey && this._definitions.length > 0 && this._definitions[0].position <= position) { | ||
// TypeScript needs to be convinced that the definition is not undefined. | ||
const { | ||
func, | ||
position: pstn | ||
} = this._definitions.shift(); | ||
while (this._ongoingJourney === journey && this._definitions.length > 0 && this._definitions[0].position <= position) { | ||
// TypeScript needs to be convinced that the definition is not undefined. | ||
const { | ||
func, | ||
position: pstn | ||
} = this._definitions.shift(); | ||
const functions = [func]; | ||
const functions = [func]; | ||
while (this._definitions.length > 0 && this._definitions[0].position === pstn) { | ||
// TypeScript needs to be convinced that the definition is not undefined. | ||
functions.push(this._definitions.shift().func); | ||
} | ||
this._position = pstn; | ||
yield Promise.all(functions.map(fnc => Promise.race([new Promise((_, reject) => setTimeout(() => { | ||
reject(new Error("Sorry, it's not allowed to initialize a promise within a scheduled function.")); | ||
})), fnc()]))); | ||
while (this._definitions.length > 0 && this._definitions[0].position === pstn) { | ||
// TypeScript needs to be convinced that the definition is not undefined. | ||
functions.push(this._definitions.shift().func); | ||
} | ||
if (this._ongoingJourney === journey) { | ||
this._ongoingJourney = null; | ||
this._position = position; | ||
} | ||
}); | ||
this._position = pstn; | ||
await Promise.all(functions.map(fnc => Promise.race([new Promise((_, reject) => setTimeout(() => { | ||
reject(new Error("Sorry, it's not allowed to initialize a promise within a scheduled function.")); | ||
})), fnc()]))); | ||
} | ||
if (this._ongoingJourney === journey) { | ||
this._ongoingJourney = null; | ||
this._position = position; | ||
} | ||
} | ||
@@ -104,0 +98,0 @@ |
@@ -8,4 +8,2 @@ "use strict"; | ||
var tslib_1 = _interopRequireWildcard(require("tslib")); | ||
var _decimal = _interopRequireDefault(require("decimal.js")); | ||
@@ -15,4 +13,2 @@ | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } | ||
class Platoon { | ||
@@ -49,34 +45,32 @@ constructor(...vehicles) { | ||
travel(distance) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
if (this._ongoingJourney !== null) { | ||
throw new Error('There is currently another journey going on.'); | ||
} | ||
async travel(distance) { | ||
if (this._ongoingJourney !== null) { | ||
throw new Error('There is currently another journey going on.'); | ||
} | ||
const journey = Symbol(); | ||
this._ongoingJourney = journey; | ||
let distanceAsDecimal = new _decimal.default(distance); | ||
const journey = Symbol(); | ||
this._ongoingJourney = journey; | ||
let distanceAsDecimal = new _decimal.default(distance); | ||
do { | ||
const distanceToNextStopover = this._vehicles.reduce((dstncSDcml, { | ||
deLorean, | ||
scale | ||
}) => { | ||
const nextStopoverAsDecimal = new _decimal.default(deLorean.nextStopover); | ||
return _decimal.default.min(nextStopoverAsDecimal.minus(deLorean.position).dividedBy(scale), dstncSDcml); | ||
}, distanceAsDecimal); | ||
do { | ||
const distanceToNextStopover = this._vehicles.reduce((dstncSDcml, { | ||
deLorean, | ||
scale | ||
}) => { | ||
const nextStopoverAsDecimal = new _decimal.default(deLorean.nextStopover); | ||
return _decimal.default.min(nextStopoverAsDecimal.minus(deLorean.position).dividedBy(scale), dstncSDcml); | ||
}, distanceAsDecimal); | ||
yield Promise.all(this._vehicles.map(({ | ||
deLorean, | ||
scale | ||
}) => { | ||
return deLorean.travel(distanceToNextStopover.times(scale).toNumber()); | ||
})); | ||
distanceAsDecimal = distanceAsDecimal.minus(distanceToNextStopover); | ||
} while (this._ongoingJourney === journey && distanceAsDecimal.greaterThan(0)); | ||
await Promise.all(this._vehicles.map(({ | ||
deLorean, | ||
scale | ||
}) => { | ||
return deLorean.travel(distanceToNextStopover.times(scale).toNumber()); | ||
})); | ||
distanceAsDecimal = distanceAsDecimal.minus(distanceToNextStopover); | ||
} while (this._ongoingJourney === journey && distanceAsDecimal.greaterThan(0)); | ||
if (this._ongoingJourney === journey) { | ||
this._ongoingJourney = null; | ||
} | ||
}); | ||
if (this._ongoingJourney === journey) { | ||
this._ongoingJourney = null; | ||
} | ||
} | ||
@@ -83,0 +77,0 @@ |
@@ -24,7 +24,7 @@ { | ||
"@babel/register": "^7.0.0", | ||
"@commitlint/cli": "^7.1.2", | ||
"@commitlint/cli": "^7.2.0", | ||
"@commitlint/config-angular": "^7.1.2", | ||
"@types/sinon": "^5.0.2", | ||
"@types/sinon": "^5.0.5", | ||
"chai": "^4.2.0", | ||
"commitizen": "^2.10.1", | ||
"commitizen": "^3.0.2", | ||
"cz-conventional-changelog": "^2.1.0", | ||
@@ -42,3 +42,3 @@ "eslint": "^5.6.1", | ||
"gruntify-eslint": "^5.0.0", | ||
"husky": "^1.0.1", | ||
"husky": "^1.1.1", | ||
"karma": "^3.0.0", | ||
@@ -55,10 +55,10 @@ "karma-chrome-launcher": "^2.2.0", | ||
"mocha": "^5.2.0", | ||
"rollup": "^0.66.2", | ||
"rollup": "^0.66.5", | ||
"rollup-plugin-babel": "^4.0.3", | ||
"sinon": "^6.3.4", | ||
"sinon": "^6.3.5", | ||
"sinon-chai": "^3.2.0", | ||
"ts-loader": "^5.2.1", | ||
"tsconfig-holy-grail": "^6.0.11", | ||
"tsconfig-holy-grail": "^7.0.2", | ||
"tslint": "^5.11.0", | ||
"tslint-config-holy-grail": "^35.1.3", | ||
"tslint-config-holy-grail": "^36.0.2", | ||
"typescript": "^3.1.1", | ||
@@ -71,5 +71,4 @@ "webpack": "^4.20.2" | ||
"files": [ | ||
"build/es2015/", | ||
"build/es2018/", | ||
"build/es5/", | ||
"build/esm/", | ||
"build/node/", | ||
@@ -92,3 +91,3 @@ "src/" | ||
"main": "build/node/module.js", | ||
"module": "build/esm/module.js", | ||
"module": "build/es2018/module.js", | ||
"name": "vehicles", | ||
@@ -103,4 +102,4 @@ "repository": { | ||
}, | ||
"types": "build/es2015/module.d.ts", | ||
"version": "3.0.11" | ||
"types": "build/es2018/module.d.ts", | ||
"version": "4.0.0" | ||
} |
39871
41
743