Prettier React Native Libraries

Reviewed By: sahrens

Differential Revision: D7961488

fbshipit-source-id: 05f9b8b0b91ae77f9040a5321ccc18f7c3c1ce9a
This commit is contained in:
Eli White
2018-05-10 19:06:46 -07:00
committed by Facebook Github Bot
parent 1e2de71290
commit d01ab66b47
301 changed files with 6259 additions and 3781 deletions

View File

@@ -4,8 +4,10 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow
*/
'use strict';
const infoLog = require('infoLog');
@@ -62,17 +64,17 @@ class TaskQueue {
}
enqueueTasks(tasks: Array<Task>): void {
tasks.forEach((task) => this.enqueue(task));
tasks.forEach(task => this.enqueue(task));
}
cancelTasks(tasksToCancel: Array<Task>): void {
// search through all tasks and remove them.
this._queueStack = this._queueStack
.map((queue) => ({
.map(queue => ({
...queue,
tasks: queue.tasks.filter((task) => tasksToCancel.indexOf(task) === -1),
tasks: queue.tasks.filter(task => tasksToCancel.indexOf(task) === -1),
}))
.filter((queue, idx) => (queue.tasks.length > 0 || idx === 0));
.filter((queue, idx) => queue.tasks.length > 0 || idx === 0);
}
/**
@@ -85,7 +87,7 @@ class TaskQueue {
* `onMoreTasks` will be called after each `PromiseTask` resolves if there are
* tasks ready to run at that point.
*/
hasTasksToProcess(): bool {
hasTasksToProcess(): boolean {
return this._getCurrentQueue().length > 0;
}
@@ -107,30 +109,36 @@ class TaskQueue {
invariant(
typeof task === 'function',
'Expected Function, SimpleTask, or PromiseTask, but got:\n' +
JSON.stringify(task, null, 2)
JSON.stringify(task, null, 2),
);
DEBUG && infoLog('run anonymous task');
task();
}
} catch (e) {
e.message = 'TaskQueue: Error with task ' + (task.name || '') + ': ' +
e.message;
e.message =
'TaskQueue: Error with task ' + (task.name || '') + ': ' + e.message;
throw e;
}
}
}
_queueStack: Array<{tasks: Array<Task>, popable: bool}>;
_queueStack: Array<{tasks: Array<Task>, popable: boolean}>;
_onMoreTasks: () => void;
_getCurrentQueue(): Array<Task> {
const stackIdx = this._queueStack.length - 1;
const queue = this._queueStack[stackIdx];
if (queue.popable &&
queue.tasks.length === 0 &&
this._queueStack.length > 1) {
if (
queue.popable &&
queue.tasks.length === 0 &&
this._queueStack.length > 1
) {
this._queueStack.pop();
DEBUG && infoLog('popped queue: ', {stackIdx, queueStackSize: this._queueStack.length});
DEBUG &&
infoLog('popped queue: ', {
stackIdx,
queueStackSize: this._queueStack.length,
});
return this._getCurrentQueue();
} else {
return queue.tasks;
@@ -146,22 +154,25 @@ class TaskQueue {
const stackIdx = this._queueStack.length - 1;
DEBUG && infoLog('push new queue: ', {stackIdx});
DEBUG && infoLog('exec gen task ' + task.name);
task.gen()
task
.gen()
.then(() => {
DEBUG && infoLog(
'onThen for gen task ' + task.name,
{stackIdx, queueStackSize: this._queueStack.length},
);
DEBUG &&
infoLog('onThen for gen task ' + task.name, {
stackIdx,
queueStackSize: this._queueStack.length,
});
this._queueStack[stackIdx].popable = true;
this.hasTasksToProcess() && this._onMoreTasks();
})
.catch((ex) => {
ex.message = `TaskQueue: Error resolving Promise in task ${task.name}: ${ex.message}`;
.catch(ex => {
ex.message = `TaskQueue: Error resolving Promise in task ${
task.name
}: ${ex.message}`;
throw ex;
})
.done();
}
}
module.exports = TaskQueue;