Skip to content

Commit 4020294

Browse files
rizalibnumsluszniak
authored andcommitted
refactor: add resetAdapter method to ResourceFetcher
Add explicit resetAdapter() method to ResourceFetcher class for cleaner API. - Add resetAdapter() static method that sets adapter to null - Update cleanupExecutorch() to use resetAdapter() instead of type assertion hack - Update error message to reference new package names (@react-native-executorch/*) This provides a cleaner, type-safe way to reset the adapter without requiring "null as unknown as ResourceFetcherAdapter" type assertion.
1 parent 9cf9cbb commit 4020294

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

packages/react-native-executorch/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export function initExecutorch(config: ExecutorchConfig) {
1313
}
1414

1515
export function cleanupExecutorch() {
16-
ResourceFetcher.setAdapter(null as unknown as ResourceFetcherAdapter);
16+
ResourceFetcher.resetAdapter();
1717
}
1818

1919
// eslint-disable no-var

packages/react-native-executorch/src/utils/ResourceFetcher.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,15 @@ export class ResourceFetcher {
6060
this.adapter = adapter;
6161
}
6262

63+
static resetAdapter() {
64+
this.adapter = null;
65+
}
66+
6367
static getAdapter(): ResourceFetcherAdapter {
6468
if (!this.adapter) {
6569
throw new RnExecutorchError(
6670
RnExecutorchErrorCode.NotImplemented,
67-
'ResourceFetcher adapter is not initialized. Please call initExecutorch({ resourceFetcher: ... }) with a valid adapter, e.g., from @rn-executorch/expo-adapter or @rn-executorch/bare-adapter.'
71+
'ResourceFetcher adapter is not initialized. Please call initExecutorch({ resourceFetcher: ... }) with a valid adapter, e.g., from @react-native-executorch/expo-resource-fetcher or @react-native-executorch/bare-resource-fetcher.'
6872
);
6973
}
7074
return this.adapter;

0 commit comments

Comments
 (0)