Skip to content

Commit cde83e9

Browse files
atscottalxhub
authored andcommitted
refactor(core): move callAndReportToErrorHandler to bootstrap file (#59793)
This function is only used in the bootstrap file and does not need to be in application_ref PR Close #59793
1 parent 3f6ccfc commit cde83e9

File tree

4 files changed

+27
-31
lines changed

4 files changed

+27
-31
lines changed

packages/core/src/application/application_ref.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ import {publishDefaultGlobalUtils as _publishDefaultGlobalUtils} from '../render
4141
import {requiresRefreshOrTraversal} from '../render3/util/view_utils';
4242
import {ViewRef as InternalViewRef} from '../render3/view_ref';
4343
import {TESTABILITY} from '../testability/testability';
44-
import {isPromise} from '../util/lang';
4544
import {NgZone} from '../zone/ng_zone';
4645

4746
import {ApplicationInitStatus} from './application_init';
@@ -176,29 +175,6 @@ export interface BootstrapOptions {
176175
/** Maximum number of times ApplicationRef will refresh all attached views in a single tick. */
177176
const MAXIMUM_REFRESH_RERUNS = 10;
178177

179-
export function _callAndReportToErrorHandler(
180-
errorHandler: ErrorHandler,
181-
ngZone: NgZone,
182-
callback: () => any,
183-
): any {
184-
try {
185-
const result = callback();
186-
if (isPromise(result)) {
187-
return result.catch((e: any) => {
188-
ngZone.runOutsideAngular(() => errorHandler.handleError(e));
189-
// rethrow as the exception handler might not do it
190-
throw e;
191-
});
192-
}
193-
194-
return result;
195-
} catch (e) {
196-
ngZone.runOutsideAngular(() => errorHandler.handleError(e));
197-
// rethrow as the exception handler might not do it
198-
throw e;
199-
}
200-
}
201-
202178
export function optionsReducer<T extends Object>(dst: T, objs: T | T[]): T {
203179
if (Array.isArray(objs)) {
204180
return objs.reduce(optionsReducer, dst);

packages/core/src/application/create_application.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {assertStandaloneComponentType} from '../render3/errors';
1515
import {EnvironmentNgModuleRefAdapter} from '../render3/ng_module_ref';
1616
import {NgZone} from '../zone/ng_zone';
1717

18-
import {_callAndReportToErrorHandler, ApplicationRef} from './application_ref';
18+
import {ApplicationRef} from './application_ref';
1919
import {ChangeDetectionScheduler} from '../change_detection/scheduling/zoneless_scheduling';
2020
import {ChangeDetectionSchedulerImpl} from '../change_detection/scheduling/zoneless_scheduling_impl';
2121
import {bootstrap} from '../platform/bootstrap';

packages/core/src/platform/bootstrap.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ import {setLocaleId} from '../render3/i18n/i18n_locale_id';
2020
import {NgZone} from '../zone/ng_zone';
2121

2222
import {ApplicationInitStatus} from '../application/application_init';
23-
import {_callAndReportToErrorHandler, ApplicationRef, remove} from '../application/application_ref';
23+
import {ApplicationRef, remove} from '../application/application_ref';
2424
import {PROVIDED_ZONELESS} from '../change_detection/scheduling/zoneless_scheduling';
2525
import {InjectionToken, Injector} from '../di';
2626
import {InternalNgModuleRef, NgModuleRef} from '../linker/ng_module_factory';
2727
import {stringify} from '../util/stringify';
28+
import {isPromise} from '../util/lang';
2829

2930
/**
3031
* InjectionToken to control root component bootstrap behavior.
@@ -200,3 +201,26 @@ function moduleDoBootstrap(
200201
}
201202
allPlatformModules.push(moduleRef);
202203
}
204+
205+
function _callAndReportToErrorHandler(
206+
errorHandler: ErrorHandler,
207+
ngZone: NgZone,
208+
callback: () => any,
209+
): any {
210+
try {
211+
const result = callback();
212+
if (isPromise(result)) {
213+
return result.catch((e: any) => {
214+
ngZone.runOutsideAngular(() => errorHandler.handleError(e));
215+
// rethrow as the exception handler might not do it
216+
throw e;
217+
});
218+
}
219+
220+
return result;
221+
} catch (e) {
222+
ngZone.runOutsideAngular(() => errorHandler.handleError(e));
223+
// rethrow as the exception handler might not do it
224+
throw e;
225+
}
226+
}

packages/core/src/platform/platform_ref.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@
77
*/
88

99
import {compileNgModuleFactory} from '../application/application_ngmodule_factory_compiler';
10-
import {
11-
_callAndReportToErrorHandler,
12-
BootstrapOptions,
13-
optionsReducer,
14-
} from '../application/application_ref';
10+
import {BootstrapOptions, optionsReducer} from '../application/application_ref';
1511
import {
1612
getNgZoneOptions,
1713
internalProvideZoneChangeDetection,

0 commit comments

Comments
 (0)