Skip to content

Commit

Permalink
fix: Fix lazy init
Browse files Browse the repository at this point in the history
  • Loading branch information
mrousavy committed Mar 27, 2024
1 parent 1350529 commit c2e610d
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 15 deletions.
5 changes: 0 additions & 5 deletions cpp/MMKVManagedBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@
#pragma once

#include <jsi/jsi.h>

#if __has_include("MMKVManagedBuffer.h")
#include "MMKVManagedBuffer.h"
#else
#include <MMKVCore/MMKVManagedBuffer.h>
#endif

using namespace facebook;

Expand Down
5 changes: 0 additions & 5 deletions cpp/MmkvHostObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@

#include "NativeMmkvModule.h"
#include <jsi/jsi.h>

#if __has_include("MMKV.h")
#include "MMKV.h"
#else
#include <MMKVCore/MMKV.h>
#endif

using namespace facebook;
using namespace mmkv;
Expand Down
5 changes: 3 additions & 2 deletions src/NativeMmkv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export interface Spec extends TurboModule {

let basePath: string | null = null;

export const MMKVTurboModule = getLazyTurboModule(() => {
function getNativeModule(): Spec | null {
if (basePath == null) {
// use default base path from the Platform (iOS/Android)
basePath = PlatformContext.getBaseDirectory();
Expand All @@ -101,4 +101,5 @@ export const MMKVTurboModule = getLazyTurboModule(() => {
}

return module;
});
}
export const MMKVTurboModule = getLazyTurboModule(getNativeModule);
7 changes: 4 additions & 3 deletions src/NativeMmkvPlatformContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface Spec extends TurboModule {
getBaseDirectory(): string;
}

export const PlatformContext = getLazyTurboModule(() =>
TurboModuleRegistry.get<Spec>('MmkvPlatformContext')
);
function getModule(): Spec | null {
return TurboModuleRegistry.get<Spec>('MmkvPlatformContext');
}
export const PlatformContext = getLazyTurboModule(getModule);
File renamed without changes.

0 comments on commit c2e610d

Please sign in to comment.