Skip to content

Commit 56c3852

Browse files
ericlewisfacebook-github-bot
authored andcommitted
add spec for HeadlessJsTaskSupport (#24907)
Summary: part of #24875 ## Changelog [General] [Added] - add TM spec for HeadlessJsTaskSupport Pull Request resolved: #24907 Reviewed By: RSNara Differential Revision: D15425720 Pulled By: fkgozali fbshipit-source-id: 2e904f265a68066918bae4f6f95494ad77654598
1 parent c44d4f9 commit 56c3852

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

Libraries/ReactNative/AppRegistry.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
const BatchedBridge = require('../BatchedBridge/BatchedBridge');
1313
const BugReporting = require('../BugReporting/BugReporting');
14-
const NativeModules = require('../BatchedBridge/NativeModules');
1514
const ReactNative = require('../Renderer/shims/ReactNative');
1615
const SceneTracker = require('../Utilities/SceneTracker');
1716

@@ -21,6 +20,8 @@ const renderApplication = require('./renderApplication');
2120
const createPerformanceLogger = require('../Utilities/createPerformanceLogger');
2221
import type {IPerformanceLogger} from '../Utilities/createPerformanceLogger';
2322

23+
import NativeHeadlessJsTaskSupport from './NativeHeadlessJsTaskSupport';
24+
2425
type Task = (taskData: any) => Promise<void>;
2526
type TaskProvider = () => Task;
2627
type TaskCanceller = () => void;
@@ -261,16 +262,22 @@ const AppRegistry = {
261262
const taskProvider = taskProviders.get(taskKey);
262263
if (!taskProvider) {
263264
console.warn(`No task registered for key ${taskKey}`);
264-
NativeModules.HeadlessJsTaskSupport.notifyTaskFinished(taskId);
265+
if (NativeHeadlessJsTaskSupport) {
266+
NativeHeadlessJsTaskSupport.notifyTaskFinished(taskId);
267+
}
265268
return;
266269
}
267270
taskProvider()(data)
268-
.then(() =>
269-
NativeModules.HeadlessJsTaskSupport.notifyTaskFinished(taskId),
270-
)
271+
.then(() => {
272+
if (NativeHeadlessJsTaskSupport) {
273+
NativeHeadlessJsTaskSupport.notifyTaskFinished(taskId);
274+
}
275+
})
271276
.catch(reason => {
272277
console.error(reason);
273-
NativeModules.HeadlessJsTaskSupport.notifyTaskFinished(taskId);
278+
if (NativeHeadlessJsTaskSupport) {
279+
NativeHeadlessJsTaskSupport.notifyTaskFinished(taskId);
280+
}
274281
});
275282
},
276283

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
* @format
9+
*/
10+
11+
'use strict';
12+
13+
import type {TurboModule} from 'RCTExport';
14+
import * as TurboModuleRegistry from 'TurboModuleRegistry';
15+
16+
export interface Spec extends TurboModule {
17+
+notifyTaskFinished: (taskId: number) => void;
18+
}
19+
20+
export default TurboModuleRegistry.get<Spec>('HeadlessJsTaskSupport');

0 commit comments

Comments
 (0)