Comparing version 2.0.0-alpha.16 to 2.0.0-alpha.17
@@ -49,4 +49,19 @@ var __extends = (this && this.__extends) || function (d, b) { | ||
var _this = this; | ||
// we have to initialize these to avoid a compiler error of using them before they are initialized | ||
var superResolve = function () { }; | ||
var superReject = function () { }; | ||
_super.call(this, function (resolve, reject) { | ||
// Don't let the Task resolve if it's been canceled | ||
superResolve = resolve; | ||
superReject = reject; | ||
}); | ||
this._state = 1 /* Pending */; | ||
this.children = []; | ||
this.canceler = function () { | ||
if (canceler) { | ||
canceler(); | ||
} | ||
_this._cancel(); | ||
}; | ||
// Don't let the Task resolve if it's been canceled | ||
try { | ||
executor(function (value) { | ||
@@ -57,3 +72,3 @@ if (_this._state === 3 /* Canceled */) { | ||
_this._state = 0 /* Fulfilled */; | ||
resolve(value); | ||
superResolve(value); | ||
}, function (reason) { | ||
@@ -64,13 +79,9 @@ if (_this._state === 3 /* Canceled */) { | ||
_this._state = 2 /* Rejected */; | ||
reject(reason); | ||
superReject(reason); | ||
}); | ||
}); | ||
this._state = 1 /* Pending */; | ||
this.children = []; | ||
this.canceler = function () { | ||
if (canceler) { | ||
canceler(); | ||
} | ||
_this._cancel(); | ||
}; | ||
} | ||
catch (reason) { | ||
this._state = 2 /* Rejected */; | ||
superReject(reason); | ||
} | ||
} | ||
@@ -128,2 +139,6 @@ Task.resolve = function (value) { | ||
Task.prototype.finally = function (callback) { | ||
// if this task is already canceled, call the task | ||
if (this._state === 3 /* Canceled */) { | ||
return Task.resolve(callback()); | ||
} | ||
var task = this.then(function (value) { return Task.resolve(callback()).then(function () { return value; }); }, function (reason) { return Task.resolve(callback()).then(function () { | ||
@@ -130,0 +145,0 @@ throw reason; |
@@ -1,2 +0,2 @@ | ||
import P from 'dojo-shim/Promise'; | ||
import Promise from 'dojo-shim/Promise'; | ||
import { Require } from 'dojo-interfaces/loader'; | ||
@@ -8,6 +8,6 @@ export interface NodeRequire { | ||
export interface Load { | ||
(require: Require, ...moduleIds: string[]): P<any[]>; | ||
(...moduleIds: string[]): P<any[]>; | ||
(require: Require, ...moduleIds: string[]): Promise<any[]>; | ||
(...moduleIds: string[]): Promise<any[]>; | ||
} | ||
declare const load: Load; | ||
export default load; |
16
load.js
@@ -6,13 +6,7 @@ (function (factory) { | ||
else if (typeof define === 'function' && define.amd) { | ||
define(["require", "exports", './global'], factory); | ||
define(["require", "exports", 'dojo-shim/Promise'], factory); | ||
} | ||
})(function (require, exports) { | ||
"use strict"; | ||
var global_1 = require('./global'); | ||
/* tslint:disable-next-line:variable-name */ | ||
var Promise = 'Promise' in global_1.default | ||
? global_1.default.Promise | ||
: typeof process === 'object' && process.versions && process.versions.node | ||
? require('dojo-shim/dist/umd/Promise').default | ||
: require('dojo-shim/Promise').default; | ||
var Promise_1 = require('dojo-shim/Promise'); | ||
var load = (function () { | ||
@@ -29,3 +23,3 @@ if (typeof module === 'object' && typeof module.exports === 'object') { | ||
} | ||
return new Promise(function (resolve, reject) { | ||
return new Promise_1.default(function (resolve, reject) { | ||
try { | ||
@@ -52,3 +46,3 @@ resolve(moduleIds.map(function (moduleId) { | ||
} | ||
return new Promise(function (resolve) { | ||
return new Promise_1.default(function (resolve) { | ||
// TODO: Error path once https://github.com/dojo/loader/issues/14 is figured out | ||
@@ -67,3 +61,3 @@ contextualRequire(moduleIds, function () { | ||
return function () { | ||
return Promise.reject(new Error('Unknown loader')); | ||
return Promise_1.default.reject(new Error('Unknown loader')); | ||
}; | ||
@@ -70,0 +64,0 @@ } |
{ | ||
"name": "dojo-core", | ||
"version": "2.0.0-alpha.16", | ||
"version": "2.0.0-alpha.17", | ||
"description": "Basic utilites for common TypeScript development", | ||
@@ -37,3 +37,3 @@ "engines": { | ||
"http-proxy": "0.10.3", | ||
"intern": "^3.3.1", | ||
"intern": "3.3.2", | ||
"istanbul": "0.4.3", | ||
@@ -40,0 +40,0 @@ "sinon": "~1.17.6", |
@@ -70,3 +70,3 @@ (function (factory) { | ||
requestOptions.headers = options.headers || {}; | ||
if (!('user-agent' in requestOptions.headers)) { | ||
if (!Object.keys(requestOptions.headers).map(function (headerName) { return headerName.toLowerCase(); }).some(function (headerName) { return headerName === 'user-agent'; })) { | ||
requestOptions.headers['user-agent'] = 'dojo/' + version + ' Node.js/' + process.version.replace(/^v/, ''); | ||
@@ -203,3 +203,6 @@ } | ||
if (options.streamTarget) { | ||
options.streamTarget.abort(error); | ||
// abort the stream, swallowing any errors, | ||
// (because we've already got an error, and we can't catch this one) | ||
options.streamTarget.abort(error).catch(function () { | ||
}); | ||
} | ||
@@ -234,3 +237,4 @@ request.abort(); | ||
else { | ||
options.streamTarget.close(); | ||
options.streamTarget.close().catch(function () { | ||
}); | ||
} | ||
@@ -247,3 +251,4 @@ }); | ||
error.response = response; | ||
writableRequest_1.abort(error); | ||
writableRequest_1.abort(error).catch(function () { | ||
}); | ||
reject(error); | ||
@@ -250,0 +255,0 @@ }); |
@@ -119,2 +119,3 @@ (function (factory) { | ||
var hasContentTypeHeader = false; | ||
var hasRequestedWithHeader = false; | ||
if (headers) { | ||
@@ -125,6 +126,9 @@ for (var header in headers) { | ||
} | ||
else if (header.toLowerCase() === 'x-requested-with') { | ||
hasRequestedWithHeader = true; | ||
} | ||
request.setRequestHeader(header, headers[header]); | ||
} | ||
} | ||
if (!headers || !('X-Requested-With' in headers)) { | ||
if (!hasRequestedWithHeader) { | ||
request.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); | ||
@@ -131,0 +135,0 @@ } |
@@ -50,4 +50,4 @@ (function (factory) { | ||
this._startedPromise = new Promise_1.default(function (resolveStarted) { | ||
var startResult = util.invokeOrNoop(_this._underlyingSource, 'start', [_this.controller]); | ||
Promise_1.default.resolve(startResult).then(function () { | ||
var startResult = util.promiseInvokeOrNoop(_this._underlyingSource, 'start', [_this.controller]); | ||
startResult.then(function () { | ||
_this._started = true; | ||
@@ -205,3 +205,6 @@ resolveStarted(); | ||
ReadableStream.prototype.error = function (error) { | ||
if (this.state !== State.Readable) { | ||
if (this.state === State.Errored) { | ||
return; | ||
} | ||
else if (this.state !== State.Readable) { | ||
throw new Error('3.5.7-1: State must be Readable'); | ||
@@ -246,5 +249,8 @@ } | ||
else if (dest.state === WritableStream_1.State.Writable) { | ||
dest.write(readResult.value); | ||
doPipe(); | ||
dest.write(readResult.value).then(function () { | ||
doPipe(); | ||
}, function () { | ||
}); | ||
} | ||
}, function () { | ||
}); | ||
@@ -254,3 +260,3 @@ } | ||
if (!options.preventCancel) { | ||
reader.cancel(reason); | ||
reader.cancel(reason).catch(function () { }); | ||
rejectPipeToPromise(reason); | ||
@@ -257,0 +263,0 @@ } |
@@ -39,2 +39,4 @@ (function (factory) { | ||
}); | ||
this._closedPromise.catch(function () { | ||
}); | ||
} | ||
@@ -78,3 +80,2 @@ Object.defineProperty(ReadableStreamReader.prototype, "closed", { | ||
ReadableStreamReader.prototype.read = function () { | ||
var _this = this; | ||
if (!isReadableStreamReader(this)) { | ||
@@ -111,12 +112,16 @@ return Promise_1.default.reject(new TypeError('3.4.4.3-1: Must be a ReadableStreamReader instance')); | ||
else { | ||
// FIXME | ||
// tslint:disable-next-line:no-var-keyword | ||
var readResolve_1 = function () { | ||
}; | ||
var readReject_1 = function () { | ||
}; | ||
var readPromise = new Promise_1.default(function (resolve, reject) { | ||
_this._readRequests.push({ | ||
promise: readPromise, | ||
resolve: resolve, | ||
reject: reject | ||
}); | ||
stream.pull(); | ||
readResolve_1 = resolve; | ||
readReject_1 = reject; | ||
}); | ||
this._readRequests.push({ | ||
promise: readPromise, | ||
resolve: readResolve_1, | ||
reject: readReject_1 | ||
}); | ||
stream.pull(); | ||
return readPromise; | ||
@@ -123,0 +128,0 @@ } |
@@ -12,3 +12,3 @@ /** | ||
dequeue(): T | null | undefined; | ||
peek(): T | undefined; | ||
peek(): T | null | undefined; | ||
} |
@@ -48,3 +48,3 @@ (function (factory) { | ||
var pair = this._queue[0]; | ||
return pair.value; | ||
return pair ? pair.value : null; | ||
}; | ||
@@ -51,0 +51,0 @@ return SizeQueue; |
@@ -45,2 +45,3 @@ (function (factory) { | ||
}); | ||
this._closedPromise.catch(function () { }); | ||
this._advancing = false; | ||
@@ -110,33 +111,33 @@ this._readyPromise = Promise_1.default.resolve(); | ||
} | ||
var writeRecord = this._queue.peek(); | ||
if (writeRecord && writeRecord.close) { | ||
// TODO: SKIP? Assert 4.3.6-3.a | ||
if (this.state !== State.Closing) { | ||
throw new Error('Invalid record'); | ||
} | ||
this._queue.dequeue(); | ||
// TODO: SKIP? Assert 4.3.6-3.c | ||
this._close(); | ||
if (this._queue.length === 0) { | ||
return; | ||
} | ||
this._writing = true; | ||
var chunk = writeRecord ? writeRecord.chunk : undefined; | ||
util.promiseInvokeOrNoop(this._underlyingSink, 'write', [chunk]).then(function () { | ||
if (_this.state !== State.Errored) { | ||
_this._writing = false; | ||
if (writeRecord && writeRecord.resolve) { | ||
writeRecord.resolve(); | ||
else { | ||
var writeRecord_1 = this._queue.peek(); | ||
if (writeRecord_1 && writeRecord_1.close) { | ||
// TODO: SKIP? Assert 4.3.6-3.a | ||
if (this.state !== State.Closing) { | ||
throw new Error('Invalid record'); | ||
} | ||
_this._queue.dequeue(); | ||
try { | ||
this._queue.dequeue(); | ||
// TODO: SKIP? Assert 4.3.6-3.c | ||
this._close(); | ||
return; | ||
} | ||
this._writing = true; | ||
var chunk = writeRecord_1 ? writeRecord_1.chunk : undefined; | ||
util.promiseInvokeOrNoop(this._underlyingSink, 'write', [chunk]).then(function () { | ||
if (_this.state !== State.Errored) { | ||
_this._writing = false; | ||
if (writeRecord_1 && writeRecord_1.resolve) { | ||
writeRecord_1.resolve(); | ||
} | ||
_this._queue.dequeue(); | ||
_this._syncStateWithQueue(); | ||
_this._advanceQueue(); | ||
} | ||
catch (error) { | ||
return _this._error(error); | ||
} | ||
_this._advanceQueue(); | ||
} | ||
}, function (error) { | ||
_this._error(error); | ||
}); | ||
}, function (error) { | ||
_this._error(error); | ||
}); | ||
} | ||
}; | ||
@@ -285,2 +286,3 @@ // 4.3.2 CloseWritableStream | ||
}); | ||
promise.catch(function () { }); | ||
// 4.2.4.6-6.b | ||
@@ -287,0 +289,0 @@ try { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
661868
146
7393