add spec for HeadlessJsTaskSupport (#24907)

Summary:
part of #24875

## Changelog

[General] [Added] - add TM spec for HeadlessJsTaskSupport
Pull Request resolved: https://github.com/facebook/react-native/pull/24907

Reviewed By: RSNara

Differential Revision: D15425720

Pulled By: fkgozali

fbshipit-source-id: 2e904f265a68066918bae4f6f95494ad77654598
This commit is contained in:
Eric Lewis 2019-05-20 18:00:34 -07:00 коммит произвёл Facebook Github Bot
Родитель c44d4f9ef6
Коммит 56c3852384
2 изменённых файлов: 33 добавлений и 6 удалений

Просмотреть файл

@ -11,7 +11,6 @@
const BatchedBridge = require('../BatchedBridge/BatchedBridge'); const BatchedBridge = require('../BatchedBridge/BatchedBridge');
const BugReporting = require('../BugReporting/BugReporting'); const BugReporting = require('../BugReporting/BugReporting');
const NativeModules = require('../BatchedBridge/NativeModules');
const ReactNative = require('../Renderer/shims/ReactNative'); const ReactNative = require('../Renderer/shims/ReactNative');
const SceneTracker = require('../Utilities/SceneTracker'); const SceneTracker = require('../Utilities/SceneTracker');
@ -21,6 +20,8 @@ const renderApplication = require('./renderApplication');
const createPerformanceLogger = require('../Utilities/createPerformanceLogger'); const createPerformanceLogger = require('../Utilities/createPerformanceLogger');
import type {IPerformanceLogger} from '../Utilities/createPerformanceLogger'; import type {IPerformanceLogger} from '../Utilities/createPerformanceLogger';
import NativeHeadlessJsTaskSupport from './NativeHeadlessJsTaskSupport';
type Task = (taskData: any) => Promise<void>; type Task = (taskData: any) => Promise<void>;
type TaskProvider = () => Task; type TaskProvider = () => Task;
type TaskCanceller = () => void; type TaskCanceller = () => void;
@ -261,16 +262,22 @@ const AppRegistry = {
const taskProvider = taskProviders.get(taskKey); const taskProvider = taskProviders.get(taskKey);
if (!taskProvider) { if (!taskProvider) {
console.warn(`No task registered for key ${taskKey}`); console.warn(`No task registered for key ${taskKey}`);
NativeModules.HeadlessJsTaskSupport.notifyTaskFinished(taskId); if (NativeHeadlessJsTaskSupport) {
NativeHeadlessJsTaskSupport.notifyTaskFinished(taskId);
}
return; return;
} }
taskProvider()(data) taskProvider()(data)
.then(() => .then(() => {
NativeModules.HeadlessJsTaskSupport.notifyTaskFinished(taskId), if (NativeHeadlessJsTaskSupport) {
) NativeHeadlessJsTaskSupport.notifyTaskFinished(taskId);
}
})
.catch(reason => { .catch(reason => {
console.error(reason); console.error(reason);
NativeModules.HeadlessJsTaskSupport.notifyTaskFinished(taskId); if (NativeHeadlessJsTaskSupport) {
NativeHeadlessJsTaskSupport.notifyTaskFinished(taskId);
}
}); });
}, },

Просмотреть файл

@ -0,0 +1,20 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
*/
'use strict';
import type {TurboModule} from 'RCTExport';
import * as TurboModuleRegistry from 'TurboModuleRegistry';
export interface Spec extends TurboModule {
+notifyTaskFinished: (taskId: number) => void;
}
export default TurboModuleRegistry.get<Spec>('HeadlessJsTaskSupport');