Skip to content

Commit

Permalink
fix: Fix "Identifier 'module' has already been declared" on web (#739)
Browse files Browse the repository at this point in the history
* Update NativeMmkvPlatformContext.ts

change module variable name to Module

* Update NativeMmkv.ts

change module variable name to Module

* Update NativeMmkvPlatformContext.ts

change variable name to mmkvPlatformModule

* Update NativeMmkv.ts

rename to mmkvModule
  • Loading branch information
arasrezaei authored Sep 9, 2024
1 parent 12c0517 commit 437fd33
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions package/src/NativeMmkv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,23 +85,23 @@ export interface Spec extends TurboModule {
createMMKV(configuration: Configuration): UnsafeObject;
}

let module: Spec | null;
let mmkvModule: Spec | null;

export function getMMKVTurboModule(): Spec {
try {
if (module == null) {
if (mmkvModule == null) {
// 1. Load MMKV TurboModule
module = TurboModuleRegistry.getEnforcing<Spec>('MmkvCxx');
mmkvModule = TurboModuleRegistry.getEnforcing<Spec>('MmkvCxx');

// 2. Get the PlatformContext TurboModule as well
const platformContext = getMMKVPlatformContextTurboModule();

// 3. Initialize it with the documents directory from platform-specific context
const basePath = platformContext.getBaseDirectory();
module.initialize(basePath);
mmkvModule.initialize(basePath);
}

return module;
return mmkvModule;
} catch (cause) {
// TurboModule could not be found!
throw new ModuleNotFoundError(cause);
Expand Down
8 changes: 4 additions & 4 deletions package/src/NativeMmkvPlatformContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ export interface Spec extends TurboModule {
getAppGroupDirectory(): string | undefined;
}

let module: Spec | null;
let mmkvPlatformModule: Spec | null;

export function getMMKVPlatformContextTurboModule(): Spec {
try {
if (module == null) {
if (mmkvPlatformModule == null) {
// 1. Get the TurboModule
module = TurboModuleRegistry.getEnforcing<Spec>('MmkvPlatformContext');
mmkvPlatformModule = TurboModuleRegistry.getEnforcing<Spec>('MmkvPlatformContext');

Check warning on line 29 in package/src/NativeMmkvPlatformContext.ts

View workflow job for this annotation

GitHub Actions / Lint JS (eslint, prettier)

Replace `'MmkvPlatformContext'` with `⏎········'MmkvPlatformContext'⏎······`
}
return module;
return mmkvPlatformModule;
} catch (e) {
// TurboModule could not be found!
throw new ModuleNotFoundError(e);
Expand Down

0 comments on commit 437fd33

Please sign in to comment.