From a199fd08c1436ae89d32dc2c694fc6798ff0dfd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Fri, 24 Jul 2015 13:44:28 +0200 Subject: [PATCH] replace es6-promise with Q --- .eslintrc | 1 + js/actions/edition_list_actions.js | 3 ++- js/actions/piece_list_actions.js | 3 ++- js/components/ascribe_media/media_player.js | 6 ++++-- js/components/ascribe_uploader/react_s3_fine_uploader.js | 2 +- js/mixins/inject_in_head_mixin.js | 6 +++--- js/utils/fetch_api_utils.js | 4 +++- js/utils/file_utils.js | 3 ++- js/utils/requests.js | 4 +++- package.json | 6 +++--- 10 files changed, 24 insertions(+), 14 deletions(-) diff --git a/.eslintrc b/.eslintrc index a2ec7f76..2312f48f 100644 --- a/.eslintrc +++ b/.eslintrc @@ -5,6 +5,7 @@ "es6": true }, "rules": { + "new-cap": [2, {newIsCap: true, capIsNew: false}], "quotes": [2, "single"], "eol-last": [0], "no-mixed-requires": [0], diff --git a/js/actions/edition_list_actions.js b/js/actions/edition_list_actions.js index 0ab07b34..2d9868c1 100644 --- a/js/actions/edition_list_actions.js +++ b/js/actions/edition_list_actions.js @@ -1,6 +1,7 @@ 'use strict'; import alt from '../alt'; +import Q from 'q'; import EditionListFetcher from '../fetchers/edition_list_fetcher.js'; @@ -28,7 +29,7 @@ class EditionListActions { pageSize = 10; } - return new Promise((resolve, reject) => { + return Q.Promise((resolve, reject) => { EditionListFetcher .fetch(pieceId, page, pageSize, orderBy, orderAsc) .then((res) => { diff --git a/js/actions/piece_list_actions.js b/js/actions/piece_list_actions.js index 390dfb98..dfb9bd44 100644 --- a/js/actions/piece_list_actions.js +++ b/js/actions/piece_list_actions.js @@ -1,6 +1,7 @@ 'use strict'; import alt from '../alt'; +import Q from 'q'; import PieceListFetcher from '../fetchers/piece_list_fetcher'; @@ -29,7 +30,7 @@ class PieceListActions { // afterwards, we can load the list - return new Promise((resolve, reject) => { + return Q.Promise((resolve, reject) => { PieceListFetcher .fetch(page, pageSize, search, orderBy, orderAsc) .then((res) => { diff --git a/js/components/ascribe_media/media_player.js b/js/components/ascribe_media/media_player.js index b4d821ae..da89f4a5 100644 --- a/js/components/ascribe_media/media_player.js +++ b/js/components/ascribe_media/media_player.js @@ -1,6 +1,8 @@ 'use strict'; import React from 'react'; +import Q from 'q'; + import InjectInHeadMixin from '../../mixins/inject_in_head_mixin'; import Panel from 'react-bootstrap/lib/Panel'; import ProgressBar from 'react-bootstrap/lib/ProgressBar'; @@ -47,7 +49,7 @@ let Image = React.createClass({ componentDidMount() { this.inject('https://code.jquery.com/jquery-2.1.4.min.js') .then(() => - Promise.all([ + Q.all([ this.inject(AppConstants.baseUrl + 'static/thirdparty/shmui/shmui.css'), this.inject(AppConstants.baseUrl + 'static/thirdparty/shmui/jquery.shmui.js') ]).then(() => { window.jQuery('.shmui-ascribe').shmui(); })); @@ -99,7 +101,7 @@ let Video = React.createClass({ }, componentDidMount() { - Promise.all([ + Q.all([ this.inject('//vjs.zencdn.net/4.12/video-js.css'), this.inject('//vjs.zencdn.net/4.12/video.js') ]).then(this.ready); diff --git a/js/components/ascribe_uploader/react_s3_fine_uploader.js b/js/components/ascribe_uploader/react_s3_fine_uploader.js index 90fe7d2c..ccaf514c 100644 --- a/js/components/ascribe_uploader/react_s3_fine_uploader.js +++ b/js/components/ascribe_uploader/react_s3_fine_uploader.js @@ -518,7 +518,7 @@ var ReactS3FineUploader = React.createClass({ // To react after the computation of all files, we define the resolvement // with the all function for iterables and essentially replace all original files // with their txt representative - Promise.all(convertedFilePromises) + Q.all(convertedFilePromises) .then((convertedFiles) => { // actually replacing all files with their txt-hash representative diff --git a/js/mixins/inject_in_head_mixin.js b/js/mixins/inject_in_head_mixin.js index b537246b..6eacacad 100644 --- a/js/mixins/inject_in_head_mixin.js +++ b/js/mixins/inject_in_head_mixin.js @@ -1,5 +1,7 @@ 'use strict'; +import Q from 'q'; + let mapAttr = { link: 'href', script: 'src' @@ -25,7 +27,7 @@ let InjectInHeadMixin = { }, injectTag(tag, src) { - let promise = new Promise((resolve, reject) => { + return Q.Promise((resolve, reject) => { if (InjectInHeadMixin.isPresent(tag, src)) { resolve(); } else { @@ -44,8 +46,6 @@ let InjectInHeadMixin = { } } }); - - return promise; }, injectStylesheet(src) { diff --git a/js/utils/fetch_api_utils.js b/js/utils/fetch_api_utils.js index db3f93fb..3ed964ba 100644 --- a/js/utils/fetch_api_utils.js +++ b/js/utils/fetch_api_utils.js @@ -1,5 +1,7 @@ 'use strict'; +import Q from 'q'; + import { sanitize } from './general_utils'; import AppConstants from '../constants/application_constants'; @@ -86,7 +88,7 @@ export function getCookie(name) { */ export function fetchImageAsBlob(url) { - return new Promise((resolve, reject) => { + return Q.Promise((resolve, reject) => { let xhr = new XMLHttpRequest(); xhr.open('GET', url, true); diff --git a/js/utils/file_utils.js b/js/utils/file_utils.js index 38507d2c..eada3a8a 100644 --- a/js/utils/file_utils.js +++ b/js/utils/file_utils.js @@ -1,5 +1,6 @@ 'use strict'; +import Q from 'q'; import SparkMD5 from 'spark-md5'; import { getLangText } from './lang_utils'; @@ -28,7 +29,7 @@ function makeTextFile(text, file) { * @return {string} regular javascript string */ export function computeHashOfFile(file) { - return new Promise((resolve, reject) => { + return Q.Promise((resolve, reject) => { let blobSlice = File.prototype.slice || File.prototype.mozSlice || File.prototype.webkitSlice; let chunkSize = 2097152; // Read in chunks of 2MB let chunks = Math.ceil(file.size / chunkSize); diff --git a/js/utils/requests.js b/js/utils/requests.js index c73df352..8705bc0f 100644 --- a/js/utils/requests.js +++ b/js/utils/requests.js @@ -1,5 +1,7 @@ 'use strict'; +import Q from 'q'; + import { argsToQueryParams, getCookie } from '../utils/fetch_api_utils'; import AppConstants from '../constants/application_constants'; @@ -22,7 +24,7 @@ class Requests { throw new Error(response.status + ' - ' + response.statusText + ' - on URL:' + response.url); } - return new Promise((resolve, reject) => { + return Q.Promise((resolve, reject) => { response.text() .then((responseText) => { // If the responses' body does not contain any data, diff --git a/package.json b/package.json index 44a7d3fa..4fdf87fb 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,6 @@ "classnames": "^1.2.2", "compression": "^1.4.4", "envify": "^3.4.0", - "es6-promise": "^2.1.1", "eslint": "^0.22.1", "eslint-plugin-react": "^2.5.0", "express": "^4.12.4", @@ -69,6 +68,7 @@ "jest-cli": "^0.4.0", "lodash": "^3.9.3", "object-assign": "^2.0.0", + "q": "^1.4.1", "raven-js": "^1.1.19", "react": "^0.13.2", "react-bootstrap": "~0.22.6", @@ -79,12 +79,12 @@ "react-textarea-autosize": "^2.2.3", "reactify": "^1.1.0", "shmui": "^0.1.0", + "spark-md5": "~1.0.0", "uglifyjs": "^2.4.10", "vinyl-buffer": "^1.0.0", "vinyl-source-stream": "^1.1.0", "watchify": "^3.1.2", - "yargs": "^3.10.0", - "spark-md5": "~1.0.0" + "yargs": "^3.10.0" }, "jest": { "scriptPreprocessor": "node_modules/babel-jest",