Split NativeAsyncStorage into NativeAsyncLocalStorage and NativeAsyncSQLiteDBStorage

Summary:
Although the interface for both NativeModules is the same, we'd like to enforce 1 `TurboModuleRegistry.get` call per NativeModule spec file. Therefore this diff splits the one spec into two.

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D24325260

fbshipit-source-id: f18718e4235b7b8ccbfc44a7e48571ecf483a36c
This commit is contained in:
Ramanpreet Nara
2020-10-15 08:49:28 -07:00
committed by Facebook GitHub Bot
parent 56c363e39a
commit 5a57a538c9
11 changed files with 278 additions and 43 deletions
@@ -20,8 +20,8 @@ import com.facebook.react.bridge.ReactModuleWithSpec;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.turbomodule.core.interfaces.TurboModule;
public abstract class NativeAsyncStorageSpec extends ReactContextBaseJavaModule implements ReactModuleWithSpec, TurboModule {
public NativeAsyncStorageSpec(ReactApplicationContext reactContext) {
public abstract class NativeAsyncLocalStorageSpec extends ReactContextBaseJavaModule implements ReactModuleWithSpec, TurboModule {
public NativeAsyncLocalStorageSpec(ReactApplicationContext reactContext) {
super(reactContext);
}
@@ -0,0 +1,45 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* <p>This source code is licensed under the MIT license found in the LICENSE file in the root
* directory of this source tree.
*
* <p>Generated by an internal genrule from Flow types.
*
* @generated
* @nolint
*/
package com.facebook.fbreact.specs;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReactModuleWithSpec;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.turbomodule.core.interfaces.TurboModule;
public abstract class NativeAsyncSQLiteDBStorageSpec extends ReactContextBaseJavaModule implements ReactModuleWithSpec, TurboModule {
public NativeAsyncSQLiteDBStorageSpec(ReactApplicationContext reactContext) {
super(reactContext);
}
@ReactMethod
public abstract void clear(Callback callback);
@ReactMethod
public abstract void getAllKeys(Callback callback);
@ReactMethod
public abstract void multiGet(ReadableArray keys, Callback callback);
@ReactMethod
public abstract void multiMerge(ReadableArray kvPairs, Callback callback);
@ReactMethod
public abstract void multiRemove(ReadableArray keys, Callback callback);
@ReactMethod
public abstract void multiSet(ReadableArray kvPairs, Callback callback);
}
@@ -618,50 +618,105 @@ namespace facebook {
namespace react {
static facebook::jsi::Value __hostFunction_NativeAsyncStorageSpecJSI_multiGet(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
static facebook::jsi::Value __hostFunction_NativeAsyncLocalStorageSpecJSI_multiGet(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
return static_cast<JavaTurboModule&>(turboModule).invokeJavaMethod(rt, VoidKind, "multiGet", "(Lcom/facebook/react/bridge/ReadableArray;Lcom/facebook/react/bridge/Callback;)V", args, count);
}
static facebook::jsi::Value __hostFunction_NativeAsyncStorageSpecJSI_multiSet(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
static facebook::jsi::Value __hostFunction_NativeAsyncLocalStorageSpecJSI_multiSet(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
return static_cast<JavaTurboModule&>(turboModule).invokeJavaMethod(rt, VoidKind, "multiSet", "(Lcom/facebook/react/bridge/ReadableArray;Lcom/facebook/react/bridge/Callback;)V", args, count);
}
static facebook::jsi::Value __hostFunction_NativeAsyncStorageSpecJSI_multiMerge(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
static facebook::jsi::Value __hostFunction_NativeAsyncLocalStorageSpecJSI_multiMerge(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
return static_cast<JavaTurboModule&>(turboModule).invokeJavaMethod(rt, VoidKind, "multiMerge", "(Lcom/facebook/react/bridge/ReadableArray;Lcom/facebook/react/bridge/Callback;)V", args, count);
}
static facebook::jsi::Value __hostFunction_NativeAsyncStorageSpecJSI_multiRemove(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
static facebook::jsi::Value __hostFunction_NativeAsyncLocalStorageSpecJSI_multiRemove(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
return static_cast<JavaTurboModule&>(turboModule).invokeJavaMethod(rt, VoidKind, "multiRemove", "(Lcom/facebook/react/bridge/ReadableArray;Lcom/facebook/react/bridge/Callback;)V", args, count);
}
static facebook::jsi::Value __hostFunction_NativeAsyncStorageSpecJSI_clear(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
static facebook::jsi::Value __hostFunction_NativeAsyncLocalStorageSpecJSI_clear(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
return static_cast<JavaTurboModule&>(turboModule).invokeJavaMethod(rt, VoidKind, "clear", "(Lcom/facebook/react/bridge/Callback;)V", args, count);
}
static facebook::jsi::Value __hostFunction_NativeAsyncStorageSpecJSI_getAllKeys(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
static facebook::jsi::Value __hostFunction_NativeAsyncLocalStorageSpecJSI_getAllKeys(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
return static_cast<JavaTurboModule&>(turboModule).invokeJavaMethod(rt, VoidKind, "getAllKeys", "(Lcom/facebook/react/bridge/Callback;)V", args, count);
}
NativeAsyncStorageSpecJSI::NativeAsyncStorageSpecJSI(const JavaTurboModule::InitParams &params)
NativeAsyncLocalStorageSpecJSI::NativeAsyncLocalStorageSpecJSI(const JavaTurboModule::InitParams &params)
: JavaTurboModule(params) {
methodMap_["multiGet"] = MethodMetadata {2, __hostFunction_NativeAsyncStorageSpecJSI_multiGet};
methodMap_["multiGet"] = MethodMetadata {2, __hostFunction_NativeAsyncLocalStorageSpecJSI_multiGet};
methodMap_["multiSet"] = MethodMetadata {2, __hostFunction_NativeAsyncStorageSpecJSI_multiSet};
methodMap_["multiSet"] = MethodMetadata {2, __hostFunction_NativeAsyncLocalStorageSpecJSI_multiSet};
methodMap_["multiMerge"] = MethodMetadata {2, __hostFunction_NativeAsyncStorageSpecJSI_multiMerge};
methodMap_["multiMerge"] = MethodMetadata {2, __hostFunction_NativeAsyncLocalStorageSpecJSI_multiMerge};
methodMap_["multiRemove"] = MethodMetadata {2, __hostFunction_NativeAsyncStorageSpecJSI_multiRemove};
methodMap_["multiRemove"] = MethodMetadata {2, __hostFunction_NativeAsyncLocalStorageSpecJSI_multiRemove};
methodMap_["clear"] = MethodMetadata {1, __hostFunction_NativeAsyncStorageSpecJSI_clear};
methodMap_["clear"] = MethodMetadata {1, __hostFunction_NativeAsyncLocalStorageSpecJSI_clear};
methodMap_["getAllKeys"] = MethodMetadata {1, __hostFunction_NativeAsyncStorageSpecJSI_getAllKeys};
methodMap_["getAllKeys"] = MethodMetadata {1, __hostFunction_NativeAsyncLocalStorageSpecJSI_getAllKeys};
}
} // namespace react
} // namespace facebook
namespace facebook {
namespace react {
static facebook::jsi::Value __hostFunction_NativeAsyncSQLiteDBStorageSpecJSI_multiGet(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
return static_cast<JavaTurboModule&>(turboModule).invokeJavaMethod(rt, VoidKind, "multiGet", "(Lcom/facebook/react/bridge/ReadableArray;Lcom/facebook/react/bridge/Callback;)V", args, count);
}
static facebook::jsi::Value __hostFunction_NativeAsyncSQLiteDBStorageSpecJSI_multiSet(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
return static_cast<JavaTurboModule&>(turboModule).invokeJavaMethod(rt, VoidKind, "multiSet", "(Lcom/facebook/react/bridge/ReadableArray;Lcom/facebook/react/bridge/Callback;)V", args, count);
}
static facebook::jsi::Value __hostFunction_NativeAsyncSQLiteDBStorageSpecJSI_multiMerge(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
return static_cast<JavaTurboModule&>(turboModule).invokeJavaMethod(rt, VoidKind, "multiMerge", "(Lcom/facebook/react/bridge/ReadableArray;Lcom/facebook/react/bridge/Callback;)V", args, count);
}
static facebook::jsi::Value __hostFunction_NativeAsyncSQLiteDBStorageSpecJSI_multiRemove(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
return static_cast<JavaTurboModule&>(turboModule).invokeJavaMethod(rt, VoidKind, "multiRemove", "(Lcom/facebook/react/bridge/ReadableArray;Lcom/facebook/react/bridge/Callback;)V", args, count);
}
static facebook::jsi::Value __hostFunction_NativeAsyncSQLiteDBStorageSpecJSI_clear(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
return static_cast<JavaTurboModule&>(turboModule).invokeJavaMethod(rt, VoidKind, "clear", "(Lcom/facebook/react/bridge/Callback;)V", args, count);
}
static facebook::jsi::Value __hostFunction_NativeAsyncSQLiteDBStorageSpecJSI_getAllKeys(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
return static_cast<JavaTurboModule&>(turboModule).invokeJavaMethod(rt, VoidKind, "getAllKeys", "(Lcom/facebook/react/bridge/Callback;)V", args, count);
}
NativeAsyncSQLiteDBStorageSpecJSI::NativeAsyncSQLiteDBStorageSpecJSI(const JavaTurboModule::InitParams &params)
: JavaTurboModule(params) {
methodMap_["multiGet"] = MethodMetadata {2, __hostFunction_NativeAsyncSQLiteDBStorageSpecJSI_multiGet};
methodMap_["multiSet"] = MethodMetadata {2, __hostFunction_NativeAsyncSQLiteDBStorageSpecJSI_multiSet};
methodMap_["multiMerge"] = MethodMetadata {2, __hostFunction_NativeAsyncSQLiteDBStorageSpecJSI_multiMerge};
methodMap_["multiRemove"] = MethodMetadata {2, __hostFunction_NativeAsyncSQLiteDBStorageSpecJSI_multiRemove};
methodMap_["clear"] = MethodMetadata {1, __hostFunction_NativeAsyncSQLiteDBStorageSpecJSI_clear};
methodMap_["getAllKeys"] = MethodMetadata {1, __hostFunction_NativeAsyncSQLiteDBStorageSpecJSI_getAllKeys};
@@ -146,12 +146,26 @@ namespace facebook {
namespace facebook {
namespace react {
/**
* C++ class for module 'AsyncStorage'
* C++ class for module 'AsyncLocalStorage'
*/
class JSI_EXPORT NativeAsyncStorageSpecJSI : public JavaTurboModule {
class JSI_EXPORT NativeAsyncLocalStorageSpecJSI : public JavaTurboModule {
public:
NativeAsyncStorageSpecJSI(const JavaTurboModule::InitParams &params);
NativeAsyncLocalStorageSpecJSI(const JavaTurboModule::InitParams &params);
};
} // namespace react
} // namespace facebook
namespace facebook {
namespace react {
/**
* C++ class for module 'AsyncSQLiteDBStorage'
*/
class JSI_EXPORT NativeAsyncSQLiteDBStorageSpecJSI : public JavaTurboModule {
public:
NativeAsyncSQLiteDBStorageSpecJSI(const JavaTurboModule::InitParams &params);
};
} // namespace react
@@ -15,7 +15,7 @@ import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;
import android.os.AsyncTask;
import com.facebook.common.logging.FLog;
import com.facebook.fbreact.specs.NativeAsyncStorageSpec;
import com.facebook.fbreact.specs.NativeAsyncSQLiteDBStorageSpec;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.GuardedAsyncTask;
@@ -32,7 +32,7 @@ import java.util.HashSet;
import java.util.concurrent.Executor;
@ReactModule(name = AsyncStorageModule.NAME)
public final class AsyncStorageModule extends NativeAsyncStorageSpec
public final class AsyncStorageModule extends NativeAsyncSQLiteDBStorageSpec
implements ModuleDataCleaner.Cleanable {
public static final String NAME = "AsyncSQLiteDBStorage";