1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-25 05:23:13 +03:00

eslint ---fix for prefer-const

This commit is contained in:
David Baker
2017-01-19 17:42:10 +00:00
parent 9b354ba99e
commit 7bca05af64
60 changed files with 1732 additions and 1732 deletions

View File

@@ -18,13 +18,13 @@ limitations under the License.
* This is an internal module. See {@link MatrixHttpApi} for the public class.
* @module http-api
*/
let q = require("q");
let utils = require("./utils");
const q = require("q");
const utils = require("./utils");
// we use our own implementation of setTimeout, so that if we get suspended in
// the middle of a /sync, we cancel the sync as soon as we awake, rather than
// waiting for the delay to elapse.
let callbacks = require("./realtime-callbacks");
const callbacks = require("./realtime-callbacks");
/*
TODO:
@@ -91,7 +91,7 @@ module.exports.MatrixHttpApi.prototype = {
* path and query parameters respectively.
*/
getContentUri: function() {
let params = {
const params = {
access_token: this.opts.accessToken,
};
return {
@@ -145,12 +145,12 @@ module.exports.MatrixHttpApi.prototype = {
// if the file doesn't have a mime type, use a default since
// the HS errors if we don't supply one.
let contentType = opts.type || file.type || 'application/octet-stream';
let fileName = opts.name || file.name;
const contentType = opts.type || file.type || 'application/octet-stream';
const fileName = opts.name || file.name;
// we used to recommend setting file.stream to the thing to upload on
// nodejs.
let body = file.stream ? file.stream : file;
const body = file.stream ? file.stream : file;
// backwards-compatibility hacks where we used to do different things
// between browser and node.
@@ -192,7 +192,7 @@ module.exports.MatrixHttpApi.prototype = {
// (browser-request doesn't support progress either, which is also kind
// of important here)
let upload = { loaded: 0, total: 0 };
const upload = { loaded: 0, total: 0 };
let promise;
// XMLHttpRequest doesn't parse JSON for us. request normally does, but
@@ -214,12 +214,12 @@ module.exports.MatrixHttpApi.prototype = {
}
if (global.XMLHttpRequest) {
let defer = q.defer();
let xhr = new global.XMLHttpRequest();
const defer = q.defer();
const xhr = new global.XMLHttpRequest();
upload.xhr = xhr;
let cb = requestCallback(defer, opts.callback, this.opts.onlyData);
const cb = requestCallback(defer, opts.callback, this.opts.onlyData);
let timeout_fn = function() {
const timeout_fn = function() {
xhr.abort();
cb(new Error('Timeout'));
};
@@ -269,7 +269,7 @@ module.exports.MatrixHttpApi.prototype = {
// dirty hack (as per _request) to allow the upload to be cancelled.
promise.abort = xhr.abort.bind(xhr);
} else {
let queryParams = {
const queryParams = {
filename: fileName,
};
@@ -283,10 +283,10 @@ module.exports.MatrixHttpApi.prototype = {
);
}
let self = this;
const self = this;
// remove the upload from the list on completion
let promise0 = promise.finally(function() {
const promise0 = promise.finally(function() {
for (let i = 0; i < self.uploads.length; ++i) {
if (self.uploads[i] === upload) {
self.uploads.splice(i, 1);
@@ -317,7 +317,7 @@ module.exports.MatrixHttpApi.prototype = {
},
idServerRequest: function(callback, method, path, params, prefix) {
let fullUri = this.opts.idBaseUrl + prefix + path;
const fullUri = this.opts.idBaseUrl + prefix + path;
if (callback !== undefined && !utils.isFunction(callback)) {
throw Error(
@@ -325,7 +325,7 @@ module.exports.MatrixHttpApi.prototype = {
);
}
let opts = {
const opts = {
uri: fullUri,
method: method,
withCredentials: false,
@@ -338,7 +338,7 @@ module.exports.MatrixHttpApi.prototype = {
opts.form = params;
}
let defer = q.defer();
const defer = q.defer();
this.opts.request(
opts,
requestCallback(defer, callback, this.opts.onlyData)
@@ -389,11 +389,11 @@ module.exports.MatrixHttpApi.prototype = {
queryParams.access_token = this.opts.accessToken;
}
let request_promise = this.request(
const request_promise = this.request(
callback, method, path, queryParams, data, opts
);
let self = this;
const self = this;
request_promise.catch(function(err) {
if (err.errcode == 'M_UNKNOWN_TOKEN') {
self.event_emitter.emit("Session.logged_out");
@@ -437,8 +437,8 @@ module.exports.MatrixHttpApi.prototype = {
*/
request: function(callback, method, path, queryParams, data, opts) {
opts = opts || {};
let prefix = opts.prefix !== undefined ? opts.prefix : this.opts.prefix;
let fullUri = this.opts.baseUrl + prefix + path;
const prefix = opts.prefix !== undefined ? opts.prefix : this.opts.prefix;
const fullUri = this.opts.baseUrl + prefix + path;
return this.requestOtherUrl(
callback, method, fullUri, queryParams, data, opts
@@ -613,9 +613,9 @@ module.exports.MatrixHttpApi.prototype = {
}
opts = opts || {};
let self = this;
const self = this;
if (this.opts.extraParams) {
for (let key in this.opts.extraParams) {
for (const key in this.opts.extraParams) {
if (!this.opts.extraParams.hasOwnProperty(key)) {
continue;
}
@@ -623,14 +623,14 @@ module.exports.MatrixHttpApi.prototype = {
}
}
let json = opts.json === undefined ? true : opts.json;
const json = opts.json === undefined ? true : opts.json;
let defer = q.defer();
const defer = q.defer();
let timeoutId;
let timedOut = false;
let req;
let localTimeoutMs = opts.localTimeoutMs || this.opts.localTimeoutMs;
const localTimeoutMs = opts.localTimeoutMs || this.opts.localTimeoutMs;
if (localTimeoutMs) {
timeoutId = callbacks.setTimeout(function() {
timedOut = true;
@@ -645,7 +645,7 @@ module.exports.MatrixHttpApi.prototype = {
}, localTimeoutMs);
}
let reqPromise = defer.promise;
const reqPromise = defer.promise;
try {
req = this.opts.request(
@@ -670,8 +670,8 @@ module.exports.MatrixHttpApi.prototype = {
// if json is falsy, we won't parse any error response, so need
// to do so before turning it into a MatrixError
let parseErrorJson = !json;
let handlerFn = requestCallback(
const parseErrorJson = !json;
const handlerFn = requestCallback(
defer, callback, self.opts.onlyData,
parseErrorJson,
opts.bodyParser
@@ -705,7 +705,7 @@ module.exports.MatrixHttpApi.prototype = {
* If parseErrorJson is true, we will JSON.parse the body if we get a 4xx error.
*
*/
let requestCallback = function(
const requestCallback = function(
defer, userDefinedCallback, onlyData,
parseErrorJson, bodyParser
) {
@@ -735,7 +735,7 @@ let requestCallback = function(
defer.reject(err);
userDefinedCallback(err);
} else {
let res = {
const res = {
code: response.statusCode,
headers: response.headers,
data: body,