replace q method calls with bluebird ones

```
find src test -name '*.js' |
    xargs perl -i -pe 's/q\.(all|defer|reject|delay|try|isFulfilled)\(/Promise.$1(/'
```
This commit is contained in:
Richard van der Hoff 2017-07-12 14:04:20 +01:00
parent 0254d2b3a2
commit 0d7cc59d99
18 changed files with 32 additions and 32 deletions

View File

@ -52,7 +52,7 @@ const MAX_HEIGHT = 600;
* and a thumbnail key.
*/
function createThumbnail(element, inputWidth, inputHeight, mimeType) {
const deferred = q.defer();
const deferred = Promise.defer();
var targetWidth = inputWidth;
var targetHeight = inputHeight;
@ -95,7 +95,7 @@ function createThumbnail(element, inputWidth, inputHeight, mimeType) {
* @return {Promise} A promise that resolves with the html image element.
*/
function loadImageElement(imageFile) {
const deferred = q.defer();
const deferred = Promise.defer();
// Load the file into an html element
const img = document.createElement("img");
@ -154,7 +154,7 @@ function infoForImageFile(matrixClient, roomId, imageFile) {
* @return {Promise} A promise that resolves with the video image element.
*/
function loadVideoElement(videoFile) {
const deferred = q.defer();
const deferred = Promise.defer();
// Load the file into an html element
const video = document.createElement("video");
@ -210,7 +210,7 @@ function infoForVideoFile(matrixClient, roomId, videoFile) {
* is read.
*/
function readFileAsArrayBuffer(file) {
const deferred = q.defer();
const deferred = Promise.defer();
const reader = new FileReader();
reader.onload = function(e) {
deferred.resolve(e.target.result);
@ -288,7 +288,7 @@ class ContentMessages {
content.info.mimetype = file.type;
}
const def = q.defer();
const def = Promise.defer();
if (file.type.indexOf('image/') == 0) {
content.msgtype = 'm.image';
infoForImageFile(matrixClient, roomId, file).then(imageInfo=>{

View File

@ -236,7 +236,7 @@ function _restoreFromLocalStorage() {
function _handleRestoreFailure(e) {
console.log("Unable to restore session", e);
const def = q.defer();
const def = Promise.defer();
const SessionRestoreErrorDialog =
sdk.getComponent('views.dialogs.SessionRestoreErrorDialog');

View File

@ -87,7 +87,7 @@ function setRoomNotifsStateMuted(roomId) {
],
}));
return q.all(promises);
return Promise.all(promises);
}
function setRoomNotifsStateUnmuted(roomId, newState) {
@ -126,7 +126,7 @@ function setRoomNotifsStateUnmuted(roomId, newState) {
promises.push(cli.setPushRuleEnabled('global', 'room', roomId, true));
}
return q.all(promises);
return Promise.all(promises);
}
function findOverrideMuteRule(roomId) {

View File

@ -53,7 +53,7 @@ class ScalarAuthClient {
}
exchangeForScalarToken(openid_token_object) {
var defer = q.defer();
var defer = Promise.defer();
var scalar_rest_url = SdkConfig.get().integrations_rest_url;
request({

View File

@ -224,7 +224,7 @@ module.exports = React.createClass({
// Used by _viewRoom before getting state from sync
this.firstSyncComplete = false;
this.firstSyncPromise = q.defer();
this.firstSyncPromise = Promise.defer();
if (this.props.config.sync_timeline_limit) {
MatrixClientPeg.opts.initialSyncLimit = this.props.config.sync_timeline_limit;
@ -1039,7 +1039,7 @@ module.exports = React.createClass({
// since we're about to start the client and therefore about
// to do the first sync
this.firstSyncComplete = false;
this.firstSyncPromise = q.defer();
this.firstSyncPromise = Promise.defer();
const cli = MatrixClientPeg.get();
// Allow the JS SDK to reap timeline events. This reduces the amount of

View File

@ -316,7 +316,7 @@ module.exports = React.createClass({
_refreshFromServer: function() {
const self = this;
q.all([
Promise.all([
UserSettingsStore.loadProfileInfo(), UserSettingsStore.loadThreePids(),
]).done(function(resps) {
self.setState({

View File

@ -498,7 +498,7 @@ module.exports = React.createClass({
}
// wait a bit to let the user finish typing
return q.delay(500).then(() => {
return Promise.delay(500).then(() => {
if (cancelled) return null;
return MatrixClientPeg.get().lookupThreePid(medium, address);
}).then((res) => {

View File

@ -104,7 +104,7 @@ module.exports = React.createClass({
}
if (oldCanonicalAlias !== this.state.canonicalAlias) {
console.log("AliasSettings: Updating canonical alias");
promises = [q.all(promises).then(
promises = [Promise.all(promises).then(
MatrixClientPeg.get().sendStateEvent(
this.props.roomId, "m.room.canonical_alias", {
alias: this.state.canonicalAlias

View File

@ -73,7 +73,7 @@ export default class Autocomplete extends React.Component {
autocompleteDelay = 0;
}
const deferred = Q.defer();
const deferred = Promise.defer();
this.debounceCompletionsRequest = setTimeout(() => {
this.processQuery(query, selection).then(() => {
deferred.resolve();
@ -176,7 +176,7 @@ export default class Autocomplete extends React.Component {
}
forceComplete() {
const done = Q.defer();
const done = Promise.defer();
this.setState({
forceComplete: true,
hide: false,

View File

@ -184,7 +184,7 @@ module.exports = React.createClass({
},
save: function() {
var stateWasSetDefer = q.defer();
var stateWasSetDefer = Promise.defer();
// the caller may have JUST called setState on stuff, so we need to re-render before saving
// else we won't use the latest values of things.
// We can be a bit cheeky here and set a loading flag, and listen for the callback on that
@ -282,7 +282,7 @@ module.exports = React.createClass({
// color scheme
var p;
p = this.saveColor();
if (!q.isFulfilled(p)) {
if (!Promise.isFulfilled(p)) {
promises.push(p);
}
@ -294,7 +294,7 @@ module.exports = React.createClass({
// encryption
p = this.saveEnableEncryption();
if (!q.isFulfilled(p)) {
if (!Promise.isFulfilled(p)) {
promises.push(p);
}

View File

@ -161,7 +161,7 @@ module.exports = React.createClass({
},
_optionallySetEmail: function() {
const deferred = q.defer();
const deferred = Promise.defer();
// Ask for an email otherwise the user has no way to reset their password
const SetEmailDialog = sdk.getComponent("dialogs.SetEmailDialog");
Modal.createDialog(SetEmailDialog, {

View File

@ -231,7 +231,7 @@ export function getCurrentLanguage() {
}
function getLangsJson() {
const deferred = q.defer();
const deferred = Promise.defer();
request(
{ method: "GET", url: i18nFolder + 'languages.json' },
@ -247,7 +247,7 @@ function getLangsJson() {
}
function getLanguage(langPath) {
const deferred = q.defer();
const deferred = Promise.defer();
let response_return = {};
request(

View File

@ -28,7 +28,7 @@ import Promise from 'bluebird';
* @return {Promise} A promise that resolves with the data:// URI.
*/
export function readBlobAsDataUri(file) {
var deferred = q.defer();
var deferred = Promise.defer();
var reader = new FileReader();
reader.onload = function(e) {
deferred.resolve(e.target.result);

View File

@ -55,7 +55,7 @@ export default class MultiInviter {
this.errorTexts[addr] = 'Unrecognised address';
}
}
this.deferred = q.defer();
this.deferred = Promise.defer();
this._inviteMore(0);
return this.deferred.promise;

View File

@ -74,7 +74,7 @@ var Tester = React.createClass({
/* returns a promise which will resolve when the fill happens */
awaitFill: function(dir) {
console.log("ScrollPanel Tester: awaiting " + dir + " fill");
var defer = q.defer();
var defer = Promise.defer();
this._fillDefers[dir] = defer;
return defer.promise;
},
@ -94,7 +94,7 @@ var Tester = React.createClass({
/* returns a promise which will resolve when a scroll event happens */
awaitScroll: function() {
console.log("Awaiting scroll");
this._scrollDefer = q.defer();
this._scrollDefer = Promise.defer();
return this._scrollDefer.promise;
},

View File

@ -147,18 +147,18 @@ describe('TimelinePanel', function() {
if(!panel.state.forwardPaginating)
return Promise.resolve();
else
return q.delay(0).then(awaitPaginationCompletion);
return Promise.delay(0).then(awaitPaginationCompletion);
};
// helper function which will return a promise which resolves when
// the TimelinePanel fires a scroll event
var awaitScroll = function() {
scrollDefer = q.defer();
scrollDefer = Promise.defer();
return scrollDefer.promise;
};
// let the first round of pagination finish off
q.delay(5).then(() => {
Promise.delay(5).then(() => {
expect(panel.state.canBackPaginate).toBe(false);
expect(scryEventTiles(panel).length).toEqual(N_EVENTS);
@ -279,7 +279,7 @@ describe('TimelinePanel', function() {
// helper function which will return a promise which resolves when
// the TimelinePanel fires a scroll event
var awaitScroll = function() {
scrollDefer = q.defer();
scrollDefer = Promise.defer();
return scrollDefer.promise.then(() => {
console.log("got scroll event; scrollTop now " +

View File

@ -110,7 +110,7 @@ describe('InteractiveAuthDialog', function () {
);
// let the request complete
return q.delay(1);
return Promise.delay(1);
}).then(() => {
expect(onFinished.callCount).toEqual(1);
expect(onFinished.calledWithExactly(true, {a:1})).toBe(true);

View File

@ -47,7 +47,7 @@ describe('MessageComposerInput', () => {
// warnings
// (please can we make the components not setState() after
// they are unmounted?)
Q.delay(10).done(() => {
Promise.delay(10).done(() => {
if (parentDiv) {
ReactDOM.unmountComponentAtNode(parentDiv);
parentDiv.remove();