Comparing version 2.0.0-alpha.9 to 2.0.0-alpha.10
@@ -29,3 +29,5 @@ (function (factory) { | ||
// add to the beginning | ||
dispatcher.before = advised; | ||
if (dispatcher) { | ||
dispatcher.before = advised; | ||
} | ||
advised.next = previous; | ||
@@ -40,4 +42,4 @@ previous.previous = advised; | ||
return lang_1.createHandle(function () { | ||
var previous = advised.previous; | ||
var next = advised.next; | ||
var previous = advised ? advised.previous : null; | ||
var next = advised ? advised.next : null; | ||
if (!previous && !next) { | ||
@@ -57,3 +59,6 @@ dispatcher[type] = null; | ||
} | ||
dispatcher = advised.advice = advised = null; | ||
if (advised) { | ||
advised.advice = null; | ||
} | ||
dispatcher = advised = null; | ||
}); | ||
@@ -77,3 +82,3 @@ } | ||
} | ||
if (dispatcher.around) { | ||
if (dispatcher.around && dispatcher.around.advice) { | ||
results = dispatcher.around.advice(this, args); | ||
@@ -134,10 +139,13 @@ } | ||
var previous = dispatcher.around; | ||
var advised = advice(function () { | ||
return previous.advice(this, arguments); | ||
}); | ||
var advised; | ||
if (advice) { | ||
advised = advice(function () { | ||
if (previous && previous.advice) { | ||
return previous.advice(this, arguments); | ||
} | ||
}); | ||
} | ||
dispatcher.around = { | ||
advice: function (target, args) { | ||
return advised ? | ||
advised.apply(target, args) : | ||
previous.advice(target, args); | ||
return advised ? advised.apply(target, args) : previous && previous.advice ? previous.advice(target, args) : null; | ||
} | ||
@@ -176,2 +184,2 @@ }; | ||
}); | ||
//# sourceMappingURL=_debug/aspect.js.map | ||
//# sourceMappingURL=aspect.js.map |
@@ -67,9 +67,13 @@ (function (factory) { | ||
if (i >= 0) { | ||
var result = callback(currentValue, results[i], i, results); | ||
if (result.then) { | ||
result.then(next, reject); | ||
if (results) { | ||
if (currentValue) { | ||
var result = callback(currentValue, results[i], i, results); | ||
if (result.then) { | ||
result.then(next, reject); | ||
} | ||
else { | ||
next(result); | ||
} | ||
} | ||
} | ||
else { | ||
next(result); | ||
} | ||
} | ||
@@ -90,3 +94,5 @@ else { | ||
} | ||
value = results[i]; | ||
if (results) { | ||
value = results[i]; | ||
} | ||
} | ||
@@ -102,19 +108,21 @@ next(value); | ||
var pendingCount = 0; | ||
for (var i = 0; i < results.length; i++) { | ||
result = callback(results[i], i, results); | ||
if (result === condition) { | ||
return resolve(result); | ||
if (results) { | ||
for (var i = 0; i < results.length; i++) { | ||
result = callback(results[i], i, results); | ||
if (result === condition) { | ||
return resolve(result); | ||
} | ||
else if (result.then) { | ||
pendingCount++; | ||
result.then(function (result) { | ||
if (result === condition) { | ||
resolve(result); | ||
} | ||
pendingCount--; | ||
if (pendingCount === 0) { | ||
resolve(!condition); | ||
} | ||
}); | ||
} | ||
} | ||
else if (result.then) { | ||
pendingCount++; | ||
result.then(function (result) { | ||
if (result === condition) { | ||
resolve(result); | ||
} | ||
pendingCount--; | ||
if (pendingCount === 0) { | ||
resolve(!condition); | ||
} | ||
}); | ||
} | ||
} | ||
@@ -144,7 +152,8 @@ if (pendingCount === 0) { | ||
function filter(items, callback) { | ||
return processValuesAndCallback(items, callback).then(function (_a) { | ||
var results = _a.results, values = _a.values; | ||
return processValuesAndCallback(items, callback).then(function (result) { | ||
var arr = []; | ||
for (var i = 0; i < results.length; i++) { | ||
results[i] && arr.push(values[i]); | ||
if (result && result.results && result.values) { | ||
for (var i = 0; i < result.results.length; i++) { | ||
result.results[i] && arr.push(result.values[i]); | ||
} | ||
} | ||
@@ -164,3 +173,3 @@ return arr; | ||
return findIndex(list, callback).then(function (i) { | ||
return i >= 0 ? list[i] : undefined; | ||
return i !== undefined && i >= 0 ? list[i] : undefined; | ||
}); | ||
@@ -177,7 +186,8 @@ } | ||
// TODO we can improve this by returning immediately | ||
return processValuesAndCallback(items, callback).then(function (_a) { | ||
var results = _a.results; | ||
for (var i = 0; i < results.length; i++) { | ||
if (results[i]) { | ||
return i; | ||
return processValuesAndCallback(items, callback).then(function (result) { | ||
if (result && result.results) { | ||
for (var i = 0; i < result.results.length; i++) { | ||
if (result.results[i]) { | ||
return i; | ||
} | ||
} | ||
@@ -197,5 +207,4 @@ } | ||
return processValuesAndCallback(items, callback) | ||
.then(function (_a) { | ||
var results = _a.results; | ||
return results; | ||
.then(function (result) { | ||
return result ? result.results : null; | ||
}); | ||
@@ -242,2 +251,2 @@ } | ||
}); | ||
//# sourceMappingURL=../_debug/async/iteration.js.map | ||
//# sourceMappingURL=iteration.js.map |
@@ -120,2 +120,4 @@ var __extends = (this && this.__extends) || function (d, b) { | ||
var _this = this; | ||
// FIXME | ||
// tslint:disable-next-line:no-var-keyword | ||
var task = _super.prototype.then.call(this, | ||
@@ -162,2 +164,2 @@ // Don't call the onFulfilled or onRejected handlers if this Task is canceled | ||
}); | ||
//# sourceMappingURL=../_debug/async/Task.js.map | ||
//# sourceMappingURL=Task.js.map |
@@ -69,2 +69,2 @@ var __extends = (this && this.__extends) || function (d, b) { | ||
}); | ||
//# sourceMappingURL=../_debug/async/timing.js.map | ||
//# sourceMappingURL=timing.js.map |
@@ -10,3 +10,3 @@ (function (factory) { | ||
"use strict"; | ||
var days = [null, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; | ||
var days = [NaN, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; | ||
var isLeapYear = (function () { | ||
@@ -324,2 +324,2 @@ var date = new Date(); | ||
}); | ||
//# sourceMappingURL=_debug/DateObject.js.map | ||
//# sourceMappingURL=DateObject.js.map |
@@ -285,2 +285,2 @@ (function (factory) { | ||
}); | ||
//# sourceMappingURL=_debug/encoding.js.map | ||
//# sourceMappingURL=encoding.js.map |
@@ -48,2 +48,2 @@ (function (factory) { | ||
}); | ||
//# sourceMappingURL=_debug/Evented.js.map | ||
//# sourceMappingURL=Evented.js.map |
@@ -14,2 +14,2 @@ (function (factory) { | ||
}); | ||
//# sourceMappingURL=_debug/global.js.map | ||
//# sourceMappingURL=global.js.map |
@@ -35,2 +35,2 @@ (function (factory) { | ||
}); | ||
//# sourceMappingURL=_debug/has.js.map | ||
//# sourceMappingURL=has.js.map |
@@ -251,2 +251,2 @@ (function (factory) { | ||
}); | ||
//# sourceMappingURL=_debug/lang.js.map | ||
//# sourceMappingURL=lang.js.map |
@@ -71,2 +71,2 @@ (function (factory) { | ||
}); | ||
//# sourceMappingURL=_debug/load.js.map | ||
//# sourceMappingURL=load.js.map |
@@ -53,2 +53,2 @@ (function (factory) { | ||
}); | ||
//# sourceMappingURL=_debug/main.js.map | ||
//# sourceMappingURL=main.js.map |
@@ -74,2 +74,4 @@ (function (factory) { | ||
function once(target, type, listener, capture) { | ||
// FIXME | ||
// tslint:disable-next-line:no-var-keyword | ||
var handle = on(target, type, function () { | ||
@@ -99,2 +101,2 @@ handle.destroy(); | ||
}); | ||
//# sourceMappingURL=_debug/on.js.map | ||
//# sourceMappingURL=on.js.map |
@@ -13,3 +13,3 @@ (function (factory) { | ||
function executeTask(item) { | ||
if (item.isActive) { | ||
if (item && item.isActive && item.callback) { | ||
item.callback(); | ||
@@ -30,24 +30,4 @@ } | ||
} | ||
// When no mechanism for registering microtasks is exposed by the environment, microtasks will | ||
// be queued and then executed in a single macrotask before the other macrotasks are executed. | ||
var checkMicroTaskQueue; | ||
var microTasks; | ||
if (!has_1.default('microtasks')) { | ||
var isMicroTaskQueued_1 = false; | ||
microTasks = []; | ||
checkMicroTaskQueue = function () { | ||
if (!isMicroTaskQueued_1) { | ||
isMicroTaskQueued_1 = true; | ||
exports.queueTask(function () { | ||
isMicroTaskQueued_1 = false; | ||
if (microTasks.length) { | ||
var item = void 0; | ||
while (item = microTasks.shift()) { | ||
executeTask(item); | ||
} | ||
} | ||
}); | ||
} | ||
}; | ||
} | ||
/** | ||
@@ -108,2 +88,22 @@ * Schedules a callback to the macrotask queue. | ||
})(); | ||
// When no mechanism for registering microtasks is exposed by the environment, microtasks will | ||
// be queued and then executed in a single macrotask before the other macrotasks are executed. | ||
if (!has_1.default('microtasks')) { | ||
var isMicroTaskQueued_1 = false; | ||
microTasks = []; | ||
checkMicroTaskQueue = function () { | ||
if (!isMicroTaskQueued_1) { | ||
isMicroTaskQueued_1 = true; | ||
exports.queueTask(function () { | ||
isMicroTaskQueued_1 = false; | ||
if (microTasks.length) { | ||
var item = void 0; | ||
while (item = microTasks.shift()) { | ||
executeTask(item); | ||
} | ||
} | ||
}); | ||
} | ||
}; | ||
} | ||
/** | ||
@@ -168,3 +168,3 @@ * Schedules an animation task with `window.requestAnimationFrame` if it exists, or with `queueTask` otherwise. | ||
var item = queue_2.shift(); | ||
if (item && item.isActive) { | ||
if (item && item.isActive && item.callback) { | ||
item.callback(); | ||
@@ -196,2 +196,2 @@ } | ||
}); | ||
//# sourceMappingURL=_debug/queue.js.map | ||
//# sourceMappingURL=queue.js.map |
@@ -33,6 +33,6 @@ (function (factory) { | ||
} | ||
var entries = this._entries.slice(0); | ||
var entries = this._entries ? this._entries.slice(0) : []; | ||
var entry; | ||
for (var i = 0; (entry = entries[i]); ++i) { | ||
if (entry.test.apply(null, args)) { | ||
if (entry.value && entry.test && entry.test.apply(null, args)) { | ||
return entry.value; | ||
@@ -64,4 +64,6 @@ } | ||
var i = 0; | ||
while ((i = entries.indexOf(entry, i)) > -1) { | ||
entries.splice(i, 1); | ||
if (entries && entry) { | ||
while ((i = entries.indexOf(entry, i)) > -1) { | ||
entries.splice(i, 1); | ||
} | ||
} | ||
@@ -77,2 +79,2 @@ test = value = entries = entry = null; | ||
}); | ||
//# sourceMappingURL=_debug/Registry.js.map | ||
//# sourceMappingURL=Registry.js.map |
@@ -26,14 +26,15 @@ var __extends = (this && this.__extends) || function (d, b) { | ||
var entryTest; | ||
if (typeof test === 'string') { | ||
var inTest = test; | ||
if (typeof inTest === 'string') { | ||
entryTest = function (response, url, options) { | ||
return test === url; | ||
return inTest === url; | ||
}; | ||
} | ||
else if (test instanceof RegExp) { | ||
else if (inTest instanceof RegExp) { | ||
entryTest = function (response, url, options) { | ||
return test.test(url); | ||
return inTest.test(url); | ||
}; | ||
} | ||
else { | ||
entryTest = test; | ||
entryTest = inTest; | ||
} | ||
@@ -62,4 +63,6 @@ return _super.prototype.register.call(this, entryTest, value, first); | ||
} | ||
actualResponse = provider(url, options); | ||
actualResponse.then(resolve, reject); | ||
if (provider) { | ||
actualResponse = provider(url, options); | ||
actualResponse.then(resolve, reject); | ||
} | ||
}); | ||
@@ -97,3 +100,3 @@ }, function () { | ||
entryTest = function (url, options) { | ||
return test.test(url); | ||
return test ? test.test(url) : null; | ||
}; | ||
@@ -155,2 +158,2 @@ } | ||
}); | ||
//# sourceMappingURL=_debug/request.js.map | ||
//# sourceMappingURL=request.js.map |
@@ -26,2 +26,2 @@ (function (factory) { | ||
}); | ||
//# sourceMappingURL=../../_debug/request/errors/RequestTimeoutError.js.map | ||
//# sourceMappingURL=RequestTimeoutError.js.map |
@@ -16,2 +16,2 @@ (function (factory) { | ||
}); | ||
//# sourceMappingURL=../_debug/request/has.js.map | ||
//# sourceMappingURL=has.js.map |
@@ -33,3 +33,2 @@ (function (factory) { | ||
ciphers: options.ciphers, | ||
headers: options.headers || {}, | ||
host: parsedUrl.host, | ||
@@ -48,2 +47,3 @@ hostname: parsedUrl.hostname, | ||
}; | ||
requestOptions.headers = options.headers || {}; | ||
if (!('user-agent' in requestOptions.headers)) { | ||
@@ -58,3 +58,5 @@ requestOptions.headers['user-agent'] = 'dojo/' + version + ' Node.js/' + process.version.replace(/^v/, ''); | ||
var _parsedUrl = urlUtil.parse(requestUrl); | ||
requestOptions.headers['host'] = _parsedUrl.host; | ||
if (_parsedUrl.host) { | ||
requestOptions.headers['host'] = _parsedUrl.host; | ||
} | ||
requestOptions.auth = _parsedUrl.auth || options.auth; | ||
@@ -77,3 +79,3 @@ } | ||
if (options.socketOptions) { | ||
if ('timeout' in options.socketOptions) { | ||
if (options.socketOptions.timeout) { | ||
request.setTimeout(options.socketOptions.timeout); | ||
@@ -113,3 +115,5 @@ } | ||
}, function (error) { | ||
options.streamTarget.abort(error); | ||
if (options.streamTarget) { | ||
options.streamTarget.abort(error); | ||
} | ||
request.abort(); | ||
@@ -194,2 +198,2 @@ error.response = response; | ||
}); | ||
//# sourceMappingURL=../_debug/request/node.js.map | ||
//# sourceMappingURL=node.js.map |
@@ -28,2 +28,2 @@ (function (factory) { | ||
}); | ||
//# sourceMappingURL=../_debug/request/util.js.map | ||
//# sourceMappingURL=util.js.map |
@@ -77,3 +77,3 @@ (function (factory) { | ||
request.open(options.method, requestUrl, !options.blockMainThread, options.user, options.password); | ||
if (has_1.default('xhr2') && options.responseType in responseTypeMap) { | ||
if (has_1.default('xhr2') && options.responseType && options.responseType in responseTypeMap) { | ||
request.responseType = responseTypeMap[options.responseType]; | ||
@@ -120,7 +120,9 @@ } | ||
var hasContentTypeHeader = false; | ||
for (var header in headers) { | ||
if (header.toLowerCase() === 'content-type') { | ||
hasContentTypeHeader = true; | ||
if (headers) { | ||
for (var header in headers) { | ||
if (header.toLowerCase() === 'content-type') { | ||
hasContentTypeHeader = true; | ||
} | ||
request.setRequestHeader(header, headers[header]); | ||
} | ||
request.setRequestHeader(header, headers[header]); | ||
} | ||
@@ -148,2 +150,2 @@ if (!headers || !('X-Requested-With' in headers)) { | ||
}); | ||
//# sourceMappingURL=../_debug/request/xhr.js.map | ||
//# sourceMappingURL=xhr.js.map |
@@ -41,8 +41,10 @@ (function (factory) { | ||
this._isProcessing = true; | ||
this._task.destroy(); | ||
this._task = null; | ||
if (this._task) { | ||
this._task.destroy(); | ||
this._task = null; | ||
} | ||
var queue = this._queue; | ||
var item; | ||
while (item = queue.shift()) { | ||
if (item.isActive) { | ||
if (item.isActive && item.callback) { | ||
item.callback(); | ||
@@ -83,2 +85,2 @@ } | ||
}); | ||
//# sourceMappingURL=_debug/Scheduler.js.map | ||
//# sourceMappingURL=Scheduler.js.map |
@@ -33,3 +33,6 @@ (function (factory) { | ||
while (this._handles.length) { | ||
this._handles.shift().destroy(); | ||
var handle = this._handles.shift(); | ||
if (handle) { | ||
handle.destroy(); | ||
} | ||
} | ||
@@ -46,2 +49,2 @@ return Promise_1.default.resolve(); | ||
}); | ||
//# sourceMappingURL=../../_debug/streams/adapters/EventedStreamSource.js.map | ||
//# sourceMappingURL=EventedStreamSource.js.map |
@@ -77,2 +77,2 @@ (function (factory) { | ||
}); | ||
//# sourceMappingURL=../../_debug/streams/adapters/ReadableNodeStreamSource.js.map | ||
//# sourceMappingURL=ReadableNodeStreamSource.js.map |
@@ -44,3 +44,3 @@ (function (factory) { | ||
// 2. put 'this' into an error state? (this._handleError) | ||
_this._nodeStream.end(null, null, function (error) { | ||
_this._nodeStream.end('', undefined, function (error) { | ||
if (error) { | ||
@@ -84,2 +84,2 @@ reject(error); | ||
}); | ||
//# sourceMappingURL=../../_debug/streams/adapters/WritableNodeStreamSink.js.map | ||
//# sourceMappingURL=WritableNodeStreamSink.js.map |
@@ -43,2 +43,2 @@ (function (factory) { | ||
}); | ||
//# sourceMappingURL=../_debug/streams/ArraySink.js.map | ||
//# sourceMappingURL=ArraySink.js.map |
@@ -53,2 +53,2 @@ (function (factory) { | ||
}); | ||
//# sourceMappingURL=../_debug/streams/ArraySource.js.map | ||
//# sourceMappingURL=ArraySource.js.map |
@@ -35,2 +35,2 @@ var __extends = (this && this.__extends) || function (d, b) { | ||
}); | ||
//# sourceMappingURL=../_debug/streams/ByteLengthQueuingStrategy.js.map | ||
//# sourceMappingURL=ByteLengthQueuingStrategy.js.map |
@@ -29,2 +29,2 @@ var __extends = (this && this.__extends) || function (d, b) { | ||
}); | ||
//# sourceMappingURL=../_debug/streams/CountQueuingStrategy.js.map | ||
//# sourceMappingURL=CountQueuingStrategy.js.map |
@@ -19,2 +19,2 @@ (function (factory) { | ||
}); | ||
//# sourceMappingURL=../_debug/streams/QueuingStrategy.js.map | ||
//# sourceMappingURL=QueuingStrategy.js.map |
@@ -178,3 +178,3 @@ (function (factory) { | ||
this.state = State.Closed; | ||
if (this.locked) { | ||
if (this.locked && this.reader) { | ||
this.reader.release(); | ||
@@ -189,3 +189,3 @@ } | ||
} | ||
if (!this.locked || !this.reader.resolveReadRequest(chunk)) { | ||
if (!this.locked || (this.reader && !this.reader.resolveReadRequest(chunk))) { | ||
try { | ||
@@ -212,3 +212,3 @@ var chunkSize = 1; | ||
this.state = State.Errored; | ||
if (this.locked) { | ||
if (this.locked && this.reader) { | ||
this.reader.release(); | ||
@@ -241,4 +241,4 @@ } | ||
lastRead = reader.read(); | ||
Promise_1.default.all([lastRead, dest.ready]).then(function (_a) { | ||
var readResult = _a[0]; | ||
Promise_1.default.all([lastRead, dest.ready]).then(function (result) { | ||
var readResult = result ? result[0] : null; | ||
if (readResult.done) { | ||
@@ -411,2 +411,2 @@ closeDest(); | ||
}); | ||
//# sourceMappingURL=../_debug/streams/ReadableStream.js.map | ||
//# sourceMappingURL=ReadableStream.js.map |
@@ -98,2 +98,2 @@ (function (factory) { | ||
}); | ||
//# sourceMappingURL=../_debug/streams/ReadableStreamController.js.map | ||
//# sourceMappingURL=ReadableStreamController.js.map |
@@ -60,4 +60,5 @@ (function (factory) { | ||
} | ||
var storedError = this._storedError; | ||
if (this.state === ReadableStream_1.State.Errored) { | ||
return Promise_1.default.reject(this._storedError); | ||
return Promise_1.default.reject(storedError); | ||
} | ||
@@ -109,5 +110,7 @@ if (this._ownerReadableStream && this._ownerReadableStream.state === ReadableStream_1.State.Readable) { | ||
else { | ||
var readPromise_1 = new Promise_1.default(function (resolve, reject) { | ||
// FIXME | ||
// tslint:disable-next-line:no-var-keyword | ||
var readPromise = new Promise_1.default(function (resolve, reject) { | ||
_this._readRequests.push({ | ||
promise: readPromise_1, | ||
promise: readPromise, | ||
resolve: resolve, | ||
@@ -118,3 +121,3 @@ reject: reject | ||
}); | ||
return readPromise_1; | ||
return readPromise; | ||
} | ||
@@ -142,3 +145,3 @@ }; | ||
var request; | ||
if (this._ownerReadableStream.state === ReadableStream_1.State.Errored) { | ||
if (this._ownerReadableStream && this._ownerReadableStream.state === ReadableStream_1.State.Errored) { | ||
this.state = ReadableStream_1.State.Errored; | ||
@@ -165,3 +168,5 @@ var e = this._ownerReadableStream.storedError; | ||
this._readRequests = []; | ||
this._ownerReadableStream.reader = undefined; | ||
if (this._ownerReadableStream) { | ||
this._ownerReadableStream.reader = undefined; | ||
} | ||
this._ownerReadableStream = undefined; | ||
@@ -176,7 +181,10 @@ }; | ||
if (this._readRequests.length > 0) { | ||
this._readRequests.shift().resolve({ | ||
value: chunk, | ||
done: false | ||
}); | ||
return true; | ||
var readRequest = this._readRequests.shift(); | ||
if (readRequest) { | ||
readRequest.resolve({ | ||
value: chunk, | ||
done: false | ||
}); | ||
return true; | ||
} | ||
} | ||
@@ -190,2 +198,2 @@ return false; | ||
}); | ||
//# sourceMappingURL=../_debug/streams/ReadableStreamReader.js.map | ||
//# sourceMappingURL=ReadableStreamReader.js.map |
@@ -79,2 +79,2 @@ var __extends = (this && this.__extends) || function (d, b) { | ||
}); | ||
//# sourceMappingURL=../_debug/streams/SeekableStream.js.map | ||
//# sourceMappingURL=SeekableStream.js.map |
@@ -89,2 +89,2 @@ var __extends = (this && this.__extends) || function (d, b) { | ||
}); | ||
//# sourceMappingURL=../_debug/streams/SeekableStreamReader.js.map | ||
//# sourceMappingURL=SeekableStreamReader.js.map |
@@ -44,3 +44,3 @@ (function (factory) { | ||
var pair = this._queue.shift(); | ||
return pair.value; | ||
return pair ? pair.value : null; | ||
}; | ||
@@ -56,2 +56,2 @@ SizeQueue.prototype.peek = function () { | ||
}); | ||
//# sourceMappingURL=../_debug/streams/SizeQueue.js.map | ||
//# sourceMappingURL=SizeQueue.js.map |
@@ -108,2 +108,2 @@ // This is a simple adaptation to TypeScript of the reference implementation (as of May 2015): | ||
}); | ||
//# sourceMappingURL=../_debug/streams/TransformStream.js.map | ||
//# sourceMappingURL=TransformStream.js.map |
@@ -128,2 +128,2 @@ (function (factory) { | ||
}); | ||
//# sourceMappingURL=../_debug/streams/util.js.map | ||
//# sourceMappingURL=util.js.map |
@@ -98,3 +98,3 @@ (function (factory) { | ||
if (!this._started) { | ||
if (!this._advancing) { | ||
if (!this._advancing && this._startedPromise) { | ||
this._advancing = true; | ||
@@ -111,3 +111,3 @@ this._startedPromise.then(function () { | ||
var writeRecord = this._queue.peek(); | ||
if (writeRecord.close) { | ||
if (writeRecord && writeRecord.close) { | ||
// TODO: SKIP? Assert 4.3.6-3.a | ||
@@ -123,6 +123,9 @@ if (this.state !== State.Closing) { | ||
this._writing = true; | ||
util.promiseInvokeOrNoop(this._underlyingSink, 'write', [writeRecord.chunk]).then(function () { | ||
var chunk = writeRecord ? writeRecord.chunk : undefined; | ||
util.promiseInvokeOrNoop(this._underlyingSink, 'write', [chunk]).then(function () { | ||
if (_this.state !== State.Errored) { | ||
_this._writing = false; | ||
writeRecord.resolve(); | ||
if (writeRecord && writeRecord.resolve) { | ||
writeRecord.resolve(); | ||
} | ||
_this._queue.dequeue(); | ||
@@ -167,3 +170,3 @@ try { | ||
writeRecord = this._queue.dequeue(); | ||
if (!writeRecord.close) { | ||
if (writeRecord && writeRecord.reject && !writeRecord.close) { | ||
writeRecord.reject(error); | ||
@@ -305,2 +308,2 @@ } | ||
}); | ||
//# sourceMappingURL=../_debug/streams/WritableStream.js.map | ||
//# sourceMappingURL=WritableStream.js.map |
@@ -89,2 +89,2 @@ (function (factory) { | ||
}); | ||
//# sourceMappingURL=_debug/stringExtras.js.map | ||
//# sourceMappingURL=stringExtras.js.map |
@@ -113,2 +113,2 @@ (function (factory) { | ||
}); | ||
//# sourceMappingURL=_debug/text.js.map | ||
//# sourceMappingURL=text.js.map |
@@ -20,3 +20,3 @@ (function (factory) { | ||
var key = void 0; | ||
var value = void 0; | ||
var value = ''; | ||
if (indexOfFirstEquals >= 0) { | ||
@@ -89,3 +89,6 @@ key = entry.slice(0, indexOfFirstEquals); | ||
else { | ||
this._list[key].push(value); | ||
var values = this._list[key]; | ||
if (values) { | ||
values.push(value); | ||
} | ||
} | ||
@@ -110,5 +113,6 @@ }; | ||
if (!this.has(key)) { | ||
return null; | ||
return undefined; | ||
} | ||
return this._list[key][0]; | ||
var value = this._list[key]; | ||
return value ? value[0] : undefined; | ||
}; | ||
@@ -122,3 +126,3 @@ /** | ||
if (!this.has(key)) { | ||
return null; | ||
return undefined; | ||
} | ||
@@ -166,6 +170,8 @@ return this._list[key]; | ||
var values = this._list[key]; | ||
var encodedKey = encodeURIComponent(key); | ||
for (var _i = 0, values_1 = values; _i < values_1.length; _i++) { | ||
var value = values_1[_i]; | ||
query.push(encodedKey + (value ? ('=' + encodeURIComponent(value)) : '')); | ||
if (values) { | ||
var encodedKey = encodeURIComponent(key); | ||
for (var _i = 0, values_1 = values; _i < values_1.length; _i++) { | ||
var value = values_1[_i]; | ||
query.push(encodedKey + (value ? ('=' + encodeURIComponent(value)) : '')); | ||
} | ||
} | ||
@@ -180,2 +186,2 @@ } | ||
}); | ||
//# sourceMappingURL=_debug/UrlSearchParams.js.map | ||
//# sourceMappingURL=UrlSearchParams.js.map |
@@ -21,4 +21,6 @@ (function (factory) { | ||
return lang_1.createHandle(function () { | ||
clearTimeout(timerId); | ||
timerId = null; | ||
if (timerId) { | ||
clearTimeout(timerId); | ||
timerId = null; | ||
} | ||
}); | ||
@@ -95,2 +97,2 @@ } | ||
}); | ||
//# sourceMappingURL=_debug/util.js.map | ||
//# sourceMappingURL=util.js.map |
{ | ||
"name": "dojo-core", | ||
"version": "2.0.0-alpha.9", | ||
"version": "2.0.0-alpha.10", | ||
"description": "Basic utilites for common TypeScript development", | ||
@@ -21,4 +21,4 @@ "homepage": "http://dojotoolkit.org", | ||
"peerDependencies": { | ||
"dojo-has": ">=2.0.0-alpha.1", | ||
"dojo-shim": ">=2.0.0-alpha.1" | ||
"dojo-has": "next", | ||
"dojo-shim": "next" | ||
}, | ||
@@ -47,4 +47,4 @@ "devDependencies": { | ||
"tslint": "^3.10.2", | ||
"typescript": "~1.8.10" | ||
"typescript": "beta" | ||
} | ||
} |
@@ -6,5 +6,5 @@ import { Handle } from './interfaces'; | ||
id?: number; | ||
advice: Function; | ||
previous?: Advised; | ||
next?: Advised; | ||
advice: Function | null; | ||
previous?: Advised | null; | ||
next?: Advised | null; | ||
receiveArguments?: boolean; | ||
@@ -16,5 +16,5 @@ } | ||
target: any; | ||
before?: Advised; | ||
before?: Advised | null; | ||
around?: Advised; | ||
after?: Advised; | ||
after?: Advised | null; | ||
} | ||
@@ -24,5 +24,5 @@ | ||
function advise(dispatcher: Dispatcher, type: string, advice: Function, receiveArguments?: boolean): Handle { | ||
function advise(dispatcher: Dispatcher | null, type: string, advice: Function | null, receiveArguments?: boolean): Handle { | ||
let previous = (<any> dispatcher)[type]; | ||
let advised: Advised = { | ||
let advised: Advised | null = { | ||
id: nextId++, | ||
@@ -43,3 +43,5 @@ advice: advice, | ||
// add to the beginning | ||
dispatcher.before = advised; | ||
if (dispatcher) { | ||
dispatcher.before = advised; | ||
} | ||
advised.next = previous; | ||
@@ -56,4 +58,4 @@ previous.previous = advised; | ||
return createHandle(function () { | ||
let previous = advised.previous; | ||
let next = advised.next; | ||
let previous = advised ? advised.previous : null; | ||
let next = advised ? advised.next : null; | ||
@@ -75,4 +77,6 @@ if (!previous && !next) { | ||
} | ||
dispatcher = advised.advice = advised = null; | ||
if (advised) { | ||
advised.advice = null; | ||
} | ||
dispatcher = advised = null; | ||
}); | ||
@@ -87,3 +91,3 @@ } | ||
// no dispatcher | ||
target[methodName] = dispatcher = <Dispatcher> function (): any { | ||
target[methodName] = dispatcher = <Dispatcher> function (this: Dispatcher): any { | ||
let executionId = nextId; | ||
@@ -101,3 +105,3 @@ let args = arguments; | ||
if (dispatcher.around) { | ||
if (dispatcher.around && dispatcher.around.advice) { | ||
results = dispatcher.around.advice(this, args); | ||
@@ -162,14 +166,17 @@ } | ||
*/ | ||
export function around(target: any, methodName: string, advice: (previous: Function) => Function): Handle { | ||
let dispatcher = getDispatcher(target, methodName); | ||
export function around(target: any, methodName: string, advice: null | ((previous: Function) => Function)): Handle { | ||
let dispatcher: Dispatcher | null = getDispatcher(target, methodName); | ||
let previous = dispatcher.around; | ||
let advised = advice(function (): any { | ||
return previous.advice(this, arguments); | ||
}); | ||
let advised: Function | null; | ||
if (advice) { | ||
advised = advice(function (this: Dispatcher): any { | ||
if (previous && previous.advice) { | ||
return previous.advice(this, arguments); | ||
} | ||
}); | ||
} | ||
dispatcher.around = { | ||
advice: function (target: any, args: any[]): any { | ||
return advised ? | ||
advised.apply(target, args) : | ||
previous.advice(target, args); | ||
return advised ? advised.apply(target, args) : previous && previous.advice ? previous.advice(target, args) : null; | ||
} | ||
@@ -176,0 +183,0 @@ }; |
@@ -6,2 +6,4 @@ import * as array from 'dojo-shim/array'; | ||
type ValuesAndResults<T, U> = { values: T[] | undefined; results: U[] | undefined; } | ||
/** | ||
@@ -14,3 +16,3 @@ * Processes all items and then applies the callback to each item and eventually returns an object containing the | ||
*/ | ||
function processValuesAndCallback<T, U>(items: Iterable<T | Promise<T>> | (T | Promise<T>)[], callback: Mapper<T, U>): Promise<{ values: T[]; results: U[] }> { | ||
function processValuesAndCallback<T, U>(items: Iterable<T | Promise<T>> | (T | Thenable<T>)[], callback: Mapper<T, U>): Promise<ValuesAndResults<T, U>> { | ||
return Promise.all<T>(items) | ||
@@ -20,3 +22,3 @@ .then(function (results) { | ||
return Promise.all<U>(pass) | ||
.then<{ values: T[]; results: U[] }>(function (pass) { | ||
.then<ValuesAndResults<T, U>>(function (pass) { | ||
return { values: results, results: pass }; | ||
@@ -53,3 +55,3 @@ }); | ||
function generalReduce<T, U>(findNextIndex: (list: ArrayLike<any>, offset?: number) => number, items: Iterable<T | Promise<T>> | (T | Promise<T>)[], callback: Reducer<T, U>, initialValue?: U): Promise<U> { | ||
function generalReduce<T, U>(findNextIndex: (list: ArrayLike<any> | undefined, offset?: number) => number, items: Iterable<T | Promise<T>> | (T | Promise<T>)[], callback: Reducer<T, U>, initialValue?: U): Promise<U> { | ||
const hasInitialValue = arguments.length > 3; | ||
@@ -63,13 +65,17 @@ return Promise.all<T>(items) | ||
let i: number; | ||
function next(currentValue: U): void { | ||
function next(currentValue: U | undefined): void { | ||
i = findNextIndex(list, i); | ||
if (i >= 0) { | ||
const result = callback(currentValue, results[i], i, results); | ||
if (results) { | ||
if (currentValue) { | ||
const result = callback(currentValue, results[i], i, results); | ||
if ( (<Thenable<U>> result).then) { | ||
(<Thenable<U>> result).then(next, reject); | ||
if ( (<Thenable<U>> result).then) { | ||
(<Thenable<U>> result).then(next, reject); | ||
} | ||
else { | ||
next(<U> result); | ||
} | ||
} | ||
} | ||
else { | ||
next(<U> result); | ||
} | ||
} | ||
@@ -81,3 +87,3 @@ else { | ||
let value: U; | ||
let value: U | undefined; | ||
if (hasInitialValue) { | ||
@@ -92,3 +98,5 @@ value = initialValue; | ||
} | ||
value = <any> results[i]; | ||
if (results) { | ||
value = <any> results[i]; | ||
} | ||
} | ||
@@ -105,19 +113,21 @@ next(value); | ||
let pendingCount = 0; | ||
for (let i = 0; i < results.length; i++) { | ||
result = callback(results[i], i, results); | ||
if (result === condition) { | ||
return resolve(result); | ||
if (results) { | ||
for (let i = 0; i < results.length; i++) { | ||
result = callback(results[i], i, results); | ||
if (result === condition) { | ||
return resolve(result); | ||
} | ||
else if ((<Thenable<boolean>> result).then) { | ||
pendingCount++; | ||
(<Thenable<boolean>> result).then(function (result) { | ||
if (result === condition) { | ||
resolve(result); | ||
} | ||
pendingCount--; | ||
if (pendingCount === 0) { | ||
resolve(!condition); | ||
} | ||
}); | ||
} | ||
} | ||
else if ((<Thenable<boolean>> result).then) { | ||
pendingCount++; | ||
(<Thenable<boolean>> result).then(function (result) { | ||
if (result === condition) { | ||
resolve(result); | ||
} | ||
pendingCount--; | ||
if (pendingCount === 0) { | ||
resolve(!condition); | ||
} | ||
}); | ||
} | ||
} | ||
@@ -148,6 +158,8 @@ if (pendingCount === 0) { | ||
export function filter<T>(items: Iterable<T | Promise<T>> | (T | Promise<T>)[], callback: Filterer<T>): Promise<T[]> { | ||
return processValuesAndCallback(items, callback).then<T[]>(function ({ results, values }) { | ||
return processValuesAndCallback(items, callback).then<T[]>(function (result) { | ||
let arr: T[] = []; | ||
for (let i = 0; i < results.length; i++) { | ||
results[i] && arr.push(values[i]); | ||
if (result && result.results && result.values) { | ||
for (let i = 0; i < result.results.length; i++) { | ||
result.results[i] && arr.push(result.values[i]); | ||
} | ||
} | ||
@@ -165,5 +177,5 @@ return arr; | ||
export function find<T>(items: Iterable<T | Promise<T>> | (T | Promise<T>)[], callback: Filterer<T>): Promise<T> { | ||
const list: (T | Promise<T>)[] = isArrayLike(items) ? items : <(T | Promise<T>)[]> array.from(items); | ||
return findIndex<T>(list, callback).then(function (i) { | ||
return i >= 0 ? list[i] : undefined; | ||
const list: (T | Thenable<T>)[] = isArrayLike(items) ? items : <(T | Thenable<T>)[]> array.from(items); | ||
return findIndex<T>(list, callback).then(function (i?: number): T | Thenable<T> | undefined { | ||
return i !== undefined && i >= 0 ? list[i] : undefined; | ||
}); | ||
@@ -178,8 +190,10 @@ } | ||
*/ | ||
export function findIndex<T>(items: Iterable<T | Promise<T>> | (T | Promise<T>)[], callback: Filterer<T>): Promise<number> { | ||
export function findIndex<T>(items: Iterable<T | Promise<T>> | (T | Thenable<T>)[], callback: Filterer<T>): Promise<number> { | ||
// TODO we can improve this by returning immediately | ||
return processValuesAndCallback(items, callback).then<number>(function ({ results }) { | ||
for (let i = 0; i < results.length; i++) { | ||
if (results[i]) { | ||
return i; | ||
return processValuesAndCallback(items, callback).then<number>(function (result: ValuesAndResults<T, boolean>) { | ||
if (result && result.results) { | ||
for (let i = 0; i < result.results.length; i++) { | ||
if (result.results[i]) { | ||
return i; | ||
} | ||
} | ||
@@ -199,4 +213,4 @@ } | ||
return processValuesAndCallback<T, U>(items, callback) | ||
.then<U[]>(function ({ results }) { | ||
return results; | ||
.then<U[]>(function (result) { | ||
return result ? result.results : null; | ||
}); | ||
@@ -212,3 +226,3 @@ } | ||
*/ | ||
export function reduce<T, U>(items: Iterable<T | Promise<T>> | (T | Promise<T>)[], callback: Reducer<T, U>, initialValue?: U): Promise<U> { | ||
export function reduce<T, U>(this: any, items: Iterable<T | Promise<T>> | (T | Promise<T>)[], callback: Reducer<T, U>, initialValue?: U): Promise<U> { | ||
let args: any[] = <any[]> array.from(arguments); | ||
@@ -219,3 +233,3 @@ args.unshift(findNextValueIndex); | ||
export function reduceRight<T, U>(items: Iterable<T | Promise<T>> | (T | Promise<T>)[], callback: Reducer<T, U>, initialValue?: U): Promise<U> { | ||
export function reduceRight<T, U>(this: any, items: Iterable<T | Promise<T>> | (T | Promise<T>)[], callback: Reducer<T, U>, initialValue?: U): Promise<U> { | ||
let args: any[] = <any[]> array.from(arguments); | ||
@@ -227,7 +241,7 @@ args.unshift(findLastValueIndex); | ||
export function series<T, U>(items: Iterable<T | Promise<T>> | (T | Promise<T>)[], operation: Mapper<T, U>): Promise<U[]> { | ||
return generalReduce(findNextValueIndex, items, function (previousValue, currentValue, index, array) { | ||
return generalReduce(findNextValueIndex, items, function (previousValue: (Thenable<U> | U)[], currentValue: T, index: number, array: T[]) { | ||
const result = operation(currentValue, index, array); | ||
if ((<Thenable<U>> result).then) { | ||
return (<Thenable<U>> result).then(function (value) { | ||
return (<Thenable<U>> result).then(function (value: U) { | ||
previousValue.push(value); | ||
@@ -234,0 +248,0 @@ return previousValue; |
@@ -139,4 +139,6 @@ import { Iterable } from 'dojo-shim/iterator'; | ||
then<U>(onFulfilled?: (value: T) => U | Thenable<U>, onRejected?: (error: Error) => U | Thenable<U>): Task<U> { | ||
const task = <Task<U>> super.then<U>( | ||
then<U>(onFulfilled?: (value: T | undefined) => U | Thenable<U>, onRejected?: (error: Error | undefined) => U | Thenable<U>): Task<U> { | ||
// FIXME | ||
// tslint:disable-next-line:no-var-keyword | ||
var task = <Task<U>> super.then<U>( | ||
// Don't call the onFulfilled or onRejected handlers if this Task is canceled | ||
@@ -143,0 +145,0 @@ function (value) { |
@@ -50,3 +50,3 @@ import Promise from 'dojo-shim/Promise'; | ||
constructor(milliseconds: number, reason?: Error) { | ||
super(function (resolve, reject) { | ||
super(function (this: DelayedRejection, resolve: Function, reject: Function) { | ||
setTimeout(reason ? reject.bind(this, reason) : reject.bind(this), milliseconds); | ||
@@ -53,0 +53,0 @@ }); |
@@ -39,3 +39,3 @@ import { Hash } from './interfaces'; | ||
const days = [ null, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ]; | ||
const days = [ NaN, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ]; | ||
@@ -112,6 +112,6 @@ const isLeapYear = (function () { | ||
value: { | ||
get isLeapYear(): boolean { | ||
get isLeapYear(this: DateObject): boolean { | ||
return isLeapYear(this.year); | ||
}, | ||
get daysInMonth(): number { | ||
get daysInMonth(this: DateObject): number { | ||
const month = this.month; | ||
@@ -118,0 +118,0 @@ |
@@ -252,3 +252,3 @@ import has from './has'; | ||
export function partial(targetFunction: (...args: any[]) => any, ...suppliedArgs: any[]): (...args: any[]) => any { | ||
return function () { | ||
return function (this: any) { | ||
const args: any[] = arguments.length ? suppliedArgs.concat(slice.call(arguments)) : suppliedArgs; | ||
@@ -270,3 +270,3 @@ | ||
return { | ||
destroy: function () { | ||
destroy: function (this: Handle) { | ||
this.destroy = function () {}; | ||
@@ -273,0 +273,0 @@ destructor.call(this); |
@@ -85,3 +85,3 @@ import { Handle, EventObject } from './interfaces'; | ||
const callback = function () { | ||
const callback = function (this: any) { | ||
listener.apply(this, arguments); | ||
@@ -127,3 +127,5 @@ }; | ||
export function once(target: any, type: any, listener: any, capture?: boolean): Handle { | ||
const handle = on(target, type, function () { | ||
// FIXME | ||
// tslint:disable-next-line:no-var-keyword | ||
var handle = on(target, type, function (this: any) { | ||
handle.destroy(); | ||
@@ -154,3 +156,3 @@ return listener.apply(this, arguments); | ||
const handle = <PausableHandle> on(target, type, function () { | ||
const handle = <PausableHandle> on(target, type, function (this: any) { | ||
if (!paused) { | ||
@@ -157,0 +159,0 @@ return listener.apply(this, arguments); |
@@ -5,4 +5,4 @@ import global from './global'; | ||
function executeTask(item: QueueItem): void { | ||
if (item.isActive) { | ||
function executeTask(item: QueueItem | undefined): void { | ||
if (item && item.isActive && item.callback) { | ||
item.callback(); | ||
@@ -14,3 +14,3 @@ } | ||
return { | ||
destroy: function () { | ||
destroy: function (this: Handle) { | ||
this.destroy = function () {}; | ||
@@ -34,30 +34,8 @@ item.isActive = false; | ||
isActive: boolean; | ||
callback: (...args: any[]) => any; | ||
callback: null | ((...args: any[]) => any); | ||
} | ||
// When no mechanism for registering microtasks is exposed by the environment, microtasks will | ||
// be queued and then executed in a single macrotask before the other macrotasks are executed. | ||
let checkMicroTaskQueue: () => void; | ||
let microTasks: QueueItem[]; | ||
if (!has('microtasks')) { | ||
let isMicroTaskQueued = false; | ||
microTasks = []; | ||
checkMicroTaskQueue = function (): void { | ||
if (!isMicroTaskQueued) { | ||
isMicroTaskQueued = true; | ||
queueTask(function () { | ||
isMicroTaskQueued = false; | ||
if (microTasks.length) { | ||
let item: QueueItem; | ||
while (item = microTasks.shift()) { | ||
executeTask(item); | ||
} | ||
} | ||
}); | ||
} | ||
}; | ||
} | ||
/** | ||
@@ -125,2 +103,25 @@ * Schedules a callback to the macrotask queue. | ||
// When no mechanism for registering microtasks is exposed by the environment, microtasks will | ||
// be queued and then executed in a single macrotask before the other macrotasks are executed. | ||
if (!has('microtasks')) { | ||
let isMicroTaskQueued = false; | ||
microTasks = []; | ||
checkMicroTaskQueue = function (): void { | ||
if (!isMicroTaskQueued) { | ||
isMicroTaskQueued = true; | ||
queueTask(function () { | ||
isMicroTaskQueued = false; | ||
if (microTasks.length) { | ||
let item: QueueItem | undefined; | ||
while (item = microTasks.shift()) { | ||
executeTask(item); | ||
} | ||
} | ||
}); | ||
} | ||
}; | ||
} | ||
/** | ||
@@ -190,3 +191,3 @@ * Schedules an animation task with `window.requestAnimationFrame` if it exists, or with `queueTask` otherwise. | ||
const item = queue.shift(); | ||
if (item && item.isActive) { | ||
if (item && item.isActive && item.callback) { | ||
item.callback(); | ||
@@ -193,0 +194,0 @@ } |
@@ -8,4 +8,4 @@ import { Handle } from './interfaces'; | ||
interface Entry<T> { | ||
test: Test; | ||
value: T; | ||
test: Test | null; | ||
value: T | null; | ||
} | ||
@@ -17,4 +17,4 @@ | ||
export default class Registry<T> { | ||
protected _defaultValue: T; | ||
private _entries: Entry<T>[]; | ||
protected _defaultValue: T | undefined; | ||
private _entries: Entry<T>[] | null; | ||
@@ -37,7 +37,7 @@ /** | ||
match(...args: any[]): T { | ||
let entries = this._entries.slice(0); | ||
const entries = this._entries ? this._entries.slice(0) : []; | ||
let entry: Entry<T>; | ||
for (let i = 0; (entry = entries[i]); ++i) { | ||
if (entry.test.apply(null, args)) { | ||
if (entry.value && entry.test && entry.test.apply(null, args)) { | ||
return entry.value; | ||
@@ -61,5 +61,5 @@ } | ||
*/ | ||
register(test: Test, value: T, first?: boolean): Handle { | ||
register(test: Test | null, value: T | null, first?: boolean): Handle { | ||
let entries = this._entries; | ||
let entry: Entry<T> = { | ||
let entry: Entry<T> | null = { | ||
test: test, | ||
@@ -72,7 +72,9 @@ value: value | ||
return { | ||
destroy: function () { | ||
destroy: function (this: Handle) { | ||
this.destroy = function (): void {}; | ||
let i = 0; | ||
while ((i = entries.indexOf(entry, i)) > -1) { | ||
entries.splice(i, 1); | ||
if (entries && entry) { | ||
while ((i = entries.indexOf(entry, i)) > -1) { | ||
entries.splice(i, 1); | ||
} | ||
} | ||
@@ -89,3 +91,3 @@ test = value = entries = entry = null; | ||
export interface Test { | ||
(...args: any[]): boolean; | ||
(...args: any[]): boolean | null; | ||
} |
@@ -12,17 +12,18 @@ import Promise from 'dojo-shim/Promise'; | ||
export class FilterRegistry extends Registry<RequestFilter> { | ||
register(test: string | RegExp | RequestFilterTest, value: RequestFilter, first?: boolean): Handle { | ||
register(test: string | RegExp | RequestFilterTest | null, value: RequestFilter, first?: boolean): Handle { | ||
let entryTest: Test; | ||
const inTest = test; | ||
if (typeof test === 'string') { | ||
if (typeof inTest === 'string') { | ||
entryTest = (response, url, options) => { | ||
return test === url; | ||
return inTest === url; | ||
}; | ||
} | ||
else if (test instanceof RegExp) { | ||
else if (inTest instanceof RegExp) { | ||
entryTest = (response, url, options) => { | ||
return test.test(url); | ||
return inTest.test(url); | ||
}; | ||
} | ||
else { | ||
entryTest = <RequestFilterTest> test; | ||
entryTest = <RequestFilterTest> inTest; | ||
} | ||
@@ -53,4 +54,6 @@ | ||
} | ||
actualResponse = provider(url, options); | ||
actualResponse.then(resolve, reject); | ||
if (provider) { | ||
actualResponse = provider(url, options); | ||
actualResponse.then(resolve, reject); | ||
} | ||
}); | ||
@@ -80,3 +83,3 @@ }, function () { | ||
register(test: string | RegExp | RequestProviderTest, value: RequestProvider, first?: boolean): Handle { | ||
register(test: string | RegExp | RequestProviderTest | null, value: RequestProvider, first?: boolean): Handle { | ||
let entryTest: Test; | ||
@@ -91,3 +94,3 @@ | ||
entryTest = (url, options) => { | ||
return test.test(url); | ||
return test ? (<RegExp> test).test(url) : null; | ||
}; | ||
@@ -124,3 +127,3 @@ } | ||
export interface RequestFilterTest extends Test { | ||
<T>(response: Response<any>, url: string, options?: RequestOptions): boolean; | ||
<T>(response: Response<any>, url: string, options?: RequestOptions): boolean | null; | ||
} | ||
@@ -146,14 +149,14 @@ | ||
export interface RequestProviderTest extends Test { | ||
(url: string, options?: RequestOptions): boolean; | ||
(url: string, options?: RequestOptions): boolean | null; | ||
} | ||
export interface Response<T> { | ||
data: T; | ||
data: T | null; | ||
nativeResponse?: any; | ||
requestOptions: RequestOptions; | ||
statusCode: number; | ||
statusText?: string; | ||
statusCode: number | null | undefined; | ||
statusText?: string | null; | ||
url: string; | ||
getHeader(name: string): string; | ||
getHeader(name: string): null | string; | ||
} | ||
@@ -160,0 +163,0 @@ |
@@ -76,3 +76,2 @@ import Task from '../async/Task'; | ||
ciphers: options.ciphers, | ||
headers: options.headers || {}, | ||
host: parsedUrl.host, | ||
@@ -92,2 +91,4 @@ hostname: parsedUrl.hostname, | ||
requestOptions.headers = options.headers || {}; | ||
if (!('user-agent' in requestOptions.headers)) { | ||
@@ -104,3 +105,5 @@ requestOptions.headers['user-agent'] = 'dojo/' + version + ' Node.js/' + process.version.replace(/^v/, ''); | ||
let _parsedUrl = urlUtil.parse(requestUrl); | ||
requestOptions.headers['host'] = _parsedUrl.host; | ||
if (_parsedUrl.host) { | ||
requestOptions.headers['host'] = _parsedUrl.host; | ||
} | ||
requestOptions.auth = _parsedUrl.auth || options.auth; | ||
@@ -116,3 +119,3 @@ } | ||
data: null, | ||
getHeader: function (name: string): string { | ||
getHeader: function (this: Response<T>, name: string): string { | ||
return (this.nativeResponse && this.nativeResponse.headers[name.toLowerCase()]) || null; | ||
@@ -127,3 +130,3 @@ }, | ||
if (options.socketOptions) { | ||
if ('timeout' in options.socketOptions) { | ||
if (options.socketOptions.timeout) { | ||
request.setTimeout(options.socketOptions.timeout); | ||
@@ -137,3 +140,3 @@ } | ||
if ('keepAlive' in options.socketOptions) { | ||
const initialDelay: number = options.socketOptions.keepAlive; | ||
const initialDelay: number | undefined = options.socketOptions.keepAlive; | ||
request.setSocketKeepAlive(initialDelay >= 0, initialDelay); | ||
@@ -174,3 +177,5 @@ } | ||
function (error: RequestError<T>) { | ||
options.streamTarget.abort(error); | ||
if (options.streamTarget) { | ||
options.streamTarget.abort(error); | ||
} | ||
request.abort(); | ||
@@ -177,0 +182,0 @@ error.response = response; |
@@ -55,3 +55,3 @@ import Task from '../async/Task'; | ||
getHeader(name: string): string { | ||
getHeader(name: string): null | string { | ||
return request.getResponseHeader(name); | ||
@@ -83,3 +83,3 @@ } | ||
if (has('xhr2') && options.responseType in responseTypeMap) { | ||
if (has('xhr2') && options.responseType && options.responseType in responseTypeMap) { | ||
request.responseType = responseTypeMap[options.responseType]; | ||
@@ -132,8 +132,9 @@ } | ||
let hasContentTypeHeader = false; | ||
for (let header in headers) { | ||
if (header.toLowerCase() === 'content-type') { | ||
hasContentTypeHeader = true; | ||
if (headers) { | ||
for (let header in headers) { | ||
if (header.toLowerCase() === 'content-type') { | ||
hasContentTypeHeader = true; | ||
} | ||
request.setRequestHeader(header, headers[header]); | ||
} | ||
request.setRequestHeader(header, headers[header]); | ||
} | ||
@@ -140,0 +141,0 @@ |
@@ -6,3 +6,3 @@ import { Handle } from './interfaces'; | ||
return { | ||
destroy: function () { | ||
destroy: function (this: Handle) { | ||
this.destroy = function () {}; | ||
@@ -22,6 +22,6 @@ item.isActive = false; | ||
protected _boundDispatch: () => void; | ||
protected _deferred: QueueItem[]; | ||
protected _deferred: QueueItem[] | null; | ||
protected _isProcessing: boolean; | ||
protected _queue: QueueItem[]; | ||
protected _task: Handle; | ||
protected _task: Handle | null; | ||
@@ -32,3 +32,3 @@ /** | ||
*/ | ||
deferWhileProcessing: boolean; | ||
deferWhileProcessing: boolean | undefined; | ||
@@ -58,10 +58,12 @@ /** | ||
this._isProcessing = true; | ||
this._task.destroy(); | ||
this._task = null; | ||
if (this._task) { | ||
this._task.destroy(); | ||
this._task = null; | ||
} | ||
const queue = this._queue; | ||
let item: QueueItem; | ||
let item: QueueItem | undefined; | ||
while (item = queue.shift()) { | ||
if (item.isActive) { | ||
if (item.isActive && item.callback) { | ||
item.callback(); | ||
@@ -73,7 +75,7 @@ } | ||
let deferred: QueueItem[] = this._deferred; | ||
let deferred: QueueItem[] | null = this._deferred; | ||
if (deferred && deferred.length) { | ||
this._deferred = null; | ||
let item: QueueItem; | ||
let item: QueueItem | undefined; | ||
while (item = deferred.shift()) { | ||
@@ -80,0 +82,0 @@ this._schedule(item); |
@@ -41,3 +41,6 @@ import Promise from 'dojo-shim/Promise'; | ||
while (this._handles.length) { | ||
this._handles.shift().destroy(); | ||
const handle = this._handles.shift(); | ||
if (handle) { | ||
handle.destroy(); | ||
} | ||
} | ||
@@ -44,0 +47,0 @@ |
@@ -11,3 +11,3 @@ import Promise from 'dojo-shim/Promise'; | ||
protected _onError: (error: Error) => void; | ||
protected _rejectWritePromise: Function; | ||
protected _rejectWritePromise: Function | undefined; | ||
@@ -52,3 +52,3 @@ constructor(nodeStream: NodeJS.WritableStream, encoding: string = '') { | ||
// 2. put 'this' into an error state? (this._handleError) | ||
this._nodeStream.end(null, null, (error: Error) => { | ||
this._nodeStream.end('', undefined, (error: Error) => { | ||
if (error) { | ||
@@ -55,0 +55,0 @@ reject(error); |
@@ -5,3 +5,3 @@ export interface Strategy<T> { | ||
*/ | ||
size?: (chunk: T) => number; | ||
size?: (chunk: T | undefined | null) => number; | ||
@@ -8,0 +8,0 @@ /** |
@@ -144,3 +144,3 @@ import Promise from 'dojo-shim/Promise'; | ||
protected _pullingPromise: Promise<void>; | ||
protected _pullingPromise: Promise<void> | undefined; | ||
protected _started: boolean; | ||
@@ -155,3 +155,3 @@ protected _startedPromise: Promise<void>; | ||
queue: SizeQueue<T>; | ||
reader: ReadableStreamReader<T>; | ||
reader: ReadableStreamReader<T> | undefined; | ||
state: State; | ||
@@ -238,3 +238,3 @@ storedError: Error; | ||
if (this.locked) { | ||
if (this.locked && this.reader) { | ||
this.reader.release(); | ||
@@ -252,3 +252,3 @@ } | ||
if (!this.locked || !this.reader.resolveReadRequest(chunk)) { | ||
if (!this.locked || (this.reader && !this.reader.resolveReadRequest(chunk))) { | ||
@@ -280,3 +280,3 @@ try { | ||
if (this.locked) { | ||
if (this.locked && this.reader) { | ||
this.reader.release(); | ||
@@ -312,3 +312,4 @@ } | ||
lastRead = reader.read(); | ||
Promise.all([ lastRead, dest.ready ]).then(function ([ readResult ]) { | ||
Promise.all([ lastRead, dest.ready ]).then(function (result) { | ||
const readResult = result ? result[0] : null; | ||
if (readResult.done) { | ||
@@ -315,0 +316,0 @@ closeDest(); |
@@ -15,3 +15,3 @@ import Promise from 'dojo-shim/Promise'; | ||
export interface ReadResult<T> { | ||
value: T; | ||
value: T | undefined; | ||
done: boolean; | ||
@@ -36,3 +36,3 @@ } | ||
private _closedPromise: Promise<void>; | ||
private _storedError: Error; | ||
private _storedError: Error | undefined; | ||
private _readRequests: ReadRequest<T>[]; | ||
@@ -42,3 +42,3 @@ private _resolveClosedPromise: () => void; | ||
protected _ownerReadableStream: ReadableStream<T>; | ||
protected _ownerReadableStream: ReadableStream<T> | undefined; | ||
@@ -82,4 +82,5 @@ state: State; | ||
const storedError = <Error> this._storedError; | ||
if (this.state === State.Errored) { | ||
return Promise.reject(this._storedError); | ||
return Promise.reject(storedError); | ||
} | ||
@@ -137,3 +138,5 @@ | ||
else { | ||
const readPromise = new Promise<ReadResult<T>>((resolve, reject) => { | ||
// FIXME | ||
// tslint:disable-next-line:no-var-keyword | ||
var readPromise = new Promise<ReadResult<T>>((resolve, reject) => { | ||
this._readRequests.push({ | ||
@@ -175,3 +178,3 @@ promise: readPromise, | ||
let request: any; | ||
if (this._ownerReadableStream.state === State.Errored) { | ||
if (this._ownerReadableStream && this._ownerReadableStream.state === State.Errored) { | ||
this.state = State.Errored; | ||
@@ -199,3 +202,5 @@ | ||
this._readRequests = []; | ||
this._ownerReadableStream.reader = undefined; | ||
if (this._ownerReadableStream) { | ||
this._ownerReadableStream.reader = undefined; | ||
} | ||
this._ownerReadableStream = undefined; | ||
@@ -211,7 +216,10 @@ } | ||
if (this._readRequests.length > 0) { | ||
this._readRequests.shift().resolve({ | ||
value: chunk, | ||
done: false | ||
}); | ||
return true; | ||
const readRequest = this._readRequests.shift(); | ||
if (readRequest) { | ||
readRequest.resolve({ | ||
value: chunk, | ||
done: false | ||
}); | ||
return true; | ||
} | ||
} | ||
@@ -218,0 +226,0 @@ return false; |
@@ -23,3 +23,3 @@ interface Pair<T> { | ||
private _queue: Pair<T>[] = []; | ||
private _queue: Pair<T | undefined>[] = []; | ||
@@ -30,12 +30,12 @@ empty() { | ||
enqueue(value: T, size: number): void { | ||
enqueue(value: T | undefined, size: number): void { | ||
this._queue.push({ value: value, size: size }); | ||
} | ||
dequeue(): T { | ||
dequeue(): T | null | undefined { | ||
const pair = this._queue.shift(); | ||
return pair.value; | ||
return pair ? pair.value : null; | ||
} | ||
peek(): T { | ||
peek(): T | undefined { | ||
const pair = this._queue[0]; | ||
@@ -42,0 +42,0 @@ return pair.value; |
@@ -21,3 +21,3 @@ // This is a simple adaptation to TypeScript of the reference implementation (as of May 2015): | ||
*/ | ||
transform(chunk: W, enqueueInReadable: (chunk: R) => void, transformDone: () => void): void; | ||
transform(chunk: W | undefined, enqueueInReadable: (chunk: R) => void, transformDone: () => void): void; | ||
@@ -60,3 +60,3 @@ /** | ||
constructor(transformer: Transform<R, W>) { | ||
let writeChunk: W; | ||
let writeChunk: W | undefined; | ||
let writeDone: () => void; | ||
@@ -63,0 +63,0 @@ let errorWritable: (error?: any) => void; |
@@ -107,7 +107,7 @@ import Promise from 'dojo-shim/Promise'; | ||
protected _started: boolean; | ||
protected _startedPromise: Promise<any>; | ||
protected _startedPromise: Promise<any> | undefined; | ||
protected _state: State; | ||
protected _storedError: Error; | ||
protected _strategy: Strategy<T>; | ||
protected _underlyingSink: Sink<T>; | ||
protected _underlyingSink: Sink<T> | undefined; | ||
protected _queue: SizeQueue<Record<T>>; | ||
@@ -148,3 +148,3 @@ protected _writing: boolean; | ||
if (!this._started) { | ||
if (!this._advancing) { | ||
if (!this._advancing && this._startedPromise) { | ||
this._advancing = true; | ||
@@ -163,5 +163,5 @@ this._startedPromise.then(() => { | ||
const writeRecord: Record<T> = this._queue.peek(); | ||
const writeRecord: Record<T> | undefined = this._queue.peek(); | ||
if (writeRecord.close) { | ||
if (writeRecord && writeRecord.close) { | ||
// TODO: SKIP? Assert 4.3.6-3.a | ||
@@ -181,6 +181,10 @@ if (this.state !== State.Closing) { | ||
util.promiseInvokeOrNoop(this._underlyingSink, 'write', [ writeRecord.chunk ]).then(() => { | ||
const chunk = writeRecord ? writeRecord.chunk : undefined; | ||
util.promiseInvokeOrNoop(this._underlyingSink, 'write', [ chunk ]).then(() => { | ||
if (this.state !== State.Errored) { | ||
this._writing = false; | ||
writeRecord.resolve(); | ||
if (writeRecord && writeRecord.resolve) { | ||
writeRecord.resolve(); | ||
} | ||
this._queue.dequeue(); | ||
@@ -227,3 +231,3 @@ | ||
let writeRecord: Record<T>; | ||
let writeRecord: Record<T> | null | undefined; | ||
@@ -233,3 +237,3 @@ while (this._queue.length) { | ||
if (!writeRecord.close) { | ||
if (writeRecord && writeRecord.reject && !writeRecord.close) { | ||
writeRecord.reject(error); | ||
@@ -372,3 +376,3 @@ } | ||
let chunkSize = 1; | ||
let writeRecord: Record<T>; | ||
let writeRecord: Record<T> | undefined; | ||
let promise = new Promise<void>(function (resolve, reject) { | ||
@@ -375,0 +379,0 @@ writeRecord = { |
@@ -31,3 +31,3 @@ import Promise from 'dojo-shim/Promise'; | ||
if (has('host-browser')) { | ||
getText = function(url: string, callback: (value: string) => void): void { | ||
getText = function(url: string, callback: (value: string | null) => void): void { | ||
request(url).then(function(response: Response<string>) { | ||
@@ -88,3 +88,3 @@ callback(response.data); | ||
let url = require.toUrl(mid); | ||
let text: string; | ||
let text: string | undefined; | ||
@@ -91,0 +91,0 @@ function finish(text: string): void { |
@@ -17,3 +17,3 @@ import { Hash } from './interfaces'; | ||
let key: string; | ||
let value: string; | ||
let value = ''; | ||
@@ -87,3 +87,3 @@ if (indexOfFirstEquals >= 0) { | ||
*/ | ||
protected _list: Hash<string[]>; | ||
protected _list: Hash<string[] | undefined>; | ||
@@ -100,3 +100,6 @@ /** | ||
else { | ||
this._list[key].push(value); | ||
const values = this._list[key]; | ||
if (values) { | ||
values.push(value); | ||
} | ||
} | ||
@@ -121,7 +124,8 @@ } | ||
*/ | ||
get(key: string): string { | ||
get(key: string): string | undefined { | ||
if (!this.has(key)) { | ||
return null; | ||
return undefined; | ||
} | ||
return this._list[key][0]; | ||
const value = this._list[key]; | ||
return value ? value[0] : undefined; | ||
} | ||
@@ -134,5 +138,5 @@ | ||
*/ | ||
getAll(key: string): string[] { | ||
getAll(key: string): string[] | undefined { | ||
if (!this.has(key)) { | ||
return null; | ||
return undefined; | ||
} | ||
@@ -188,5 +192,7 @@ return this._list[key]; | ||
const values = this._list[key]; | ||
const encodedKey = encodeURIComponent(key); | ||
for (const value of values) { | ||
query.push(encodedKey + (value ? ('=' + encodeURIComponent(value)) : '')); | ||
if (values) { | ||
const encodedKey = encodeURIComponent(key); | ||
for (const value of values) { | ||
query.push(encodedKey + (value ? ('=' + encodeURIComponent(value)) : '')); | ||
} | ||
} | ||
@@ -193,0 +199,0 @@ } |
@@ -12,7 +12,9 @@ import { Handle } from './interfaces'; | ||
export function createTimer(callback: (...args: any[]) => void, delay?: number): Handle { | ||
let timerId = setTimeout(callback, delay); | ||
let timerId: number | null = setTimeout(callback, delay); | ||
return createHandle(function () { | ||
clearTimeout(timerId); | ||
timerId = null; | ||
if (timerId) { | ||
clearTimeout(timerId); | ||
timerId = null; | ||
} | ||
}); | ||
@@ -28,3 +30,3 @@ } | ||
*/ | ||
export function debounce<T extends (...args: any[]) => void>(callback: T, delay: number): T { | ||
export function debounce<T extends (this: any, ...args: any[]) => void>(callback: T, delay: number): T { | ||
// node.d.ts clobbers setTimeout/clearTimeout with versions that return/receive NodeJS.Timer, | ||
@@ -38,3 +40,3 @@ // but browsers return/receive a number | ||
let context = this; | ||
let args = arguments; | ||
let args: IArguments | null = arguments; | ||
@@ -55,4 +57,4 @@ timer = setTimeout(function () { | ||
*/ | ||
export function throttle<T extends (...args: any[]) => void>(callback: T, delay: number): T { | ||
let ran: boolean; | ||
export function throttle<T extends (this: any, ...args: any[]) => void>(callback: T, delay: number): T { | ||
let ran: boolean | null; | ||
@@ -81,4 +83,4 @@ return <T> function () { | ||
*/ | ||
export function throttleAfter<T extends (...args: any[]) => void>(callback: T, delay: number): T { | ||
let ran: boolean; | ||
export function throttleAfter<T extends (this: any, ...args: any[]) => void>(callback: T, delay: number): T { | ||
let ran: boolean | null; | ||
@@ -93,3 +95,3 @@ return <T> function () { | ||
let context = this; | ||
let args = arguments; | ||
let args: IArguments | null = arguments; | ||
@@ -96,0 +98,0 @@ setTimeout(function () { |
{ | ||
"name": "dojo-core", | ||
"globalDependencies": { | ||
"dojo-has": "npm:dojo-has", | ||
"dojo-shim": "npm:dojo-shim" | ||
}, | ||
"devDependencies": { | ||
@@ -8,0 +4,0 @@ "chai": "registry:npm/chai#3.5.0+20160415060238", |
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
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
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
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
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
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 too big to display
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
189
12991
1
135
649194
3