Skip to content

Commit 5a57a53

Browse files
RSNarafacebook-github-bot
authored andcommitted
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
1 parent 56c363e commit 5a57a53

File tree

11 files changed

+278
-43
lines changed

11 files changed

+278
-43
lines changed

Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec-generated.mm

Lines changed: 64 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -612,49 +612,100 @@ + (RCTManagedPointer *)JS_NativeAnimatedTurboModule_EventMapping:(id)json
612612
namespace facebook {
613613
namespace react {
614614

615-
static facebook::jsi::Value __hostFunction_NativeAsyncStorageSpecJSI_multiGet(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
615+
static facebook::jsi::Value __hostFunction_NativeAsyncLocalStorageSpecJSI_multiGet(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
616616
return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, VoidKind, "multiGet", @selector(multiGet:callback:), args, count);
617617
}
618618

619-
static facebook::jsi::Value __hostFunction_NativeAsyncStorageSpecJSI_multiSet(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
619+
static facebook::jsi::Value __hostFunction_NativeAsyncLocalStorageSpecJSI_multiSet(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
620620
return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, VoidKind, "multiSet", @selector(multiSet:callback:), args, count);
621621
}
622622

623-
static facebook::jsi::Value __hostFunction_NativeAsyncStorageSpecJSI_multiMerge(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
623+
static facebook::jsi::Value __hostFunction_NativeAsyncLocalStorageSpecJSI_multiMerge(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
624624
return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, VoidKind, "multiMerge", @selector(multiMerge:callback:), args, count);
625625
}
626626

627-
static facebook::jsi::Value __hostFunction_NativeAsyncStorageSpecJSI_multiRemove(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
627+
static facebook::jsi::Value __hostFunction_NativeAsyncLocalStorageSpecJSI_multiRemove(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
628628
return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, VoidKind, "multiRemove", @selector(multiRemove:callback:), args, count);
629629
}
630630

631-
static facebook::jsi::Value __hostFunction_NativeAsyncStorageSpecJSI_clear(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
631+
static facebook::jsi::Value __hostFunction_NativeAsyncLocalStorageSpecJSI_clear(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
632632
return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, VoidKind, "clear", @selector(clear:), args, count);
633633
}
634634

635-
static facebook::jsi::Value __hostFunction_NativeAsyncStorageSpecJSI_getAllKeys(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
635+
static facebook::jsi::Value __hostFunction_NativeAsyncLocalStorageSpecJSI_getAllKeys(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
636636
return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, VoidKind, "getAllKeys", @selector(getAllKeys:), args, count);
637637
}
638638

639-
NativeAsyncStorageSpecJSI::NativeAsyncStorageSpecJSI(const ObjCTurboModule::InitParams &params)
639+
NativeAsyncLocalStorageSpecJSI::NativeAsyncLocalStorageSpecJSI(const ObjCTurboModule::InitParams &params)
640640
: ObjCTurboModule(params) {
641641

642-
methodMap_["multiGet"] = MethodMetadata {2, __hostFunction_NativeAsyncStorageSpecJSI_multiGet};
642+
methodMap_["multiGet"] = MethodMetadata {2, __hostFunction_NativeAsyncLocalStorageSpecJSI_multiGet};
643643

644644

645-
methodMap_["multiSet"] = MethodMetadata {2, __hostFunction_NativeAsyncStorageSpecJSI_multiSet};
645+
methodMap_["multiSet"] = MethodMetadata {2, __hostFunction_NativeAsyncLocalStorageSpecJSI_multiSet};
646646

647647

648-
methodMap_["multiMerge"] = MethodMetadata {2, __hostFunction_NativeAsyncStorageSpecJSI_multiMerge};
648+
methodMap_["multiMerge"] = MethodMetadata {2, __hostFunction_NativeAsyncLocalStorageSpecJSI_multiMerge};
649649

650650

651-
methodMap_["multiRemove"] = MethodMetadata {2, __hostFunction_NativeAsyncStorageSpecJSI_multiRemove};
651+
methodMap_["multiRemove"] = MethodMetadata {2, __hostFunction_NativeAsyncLocalStorageSpecJSI_multiRemove};
652652

653653

654-
methodMap_["clear"] = MethodMetadata {1, __hostFunction_NativeAsyncStorageSpecJSI_clear};
654+
methodMap_["clear"] = MethodMetadata {1, __hostFunction_NativeAsyncLocalStorageSpecJSI_clear};
655655

656656

657-
methodMap_["getAllKeys"] = MethodMetadata {1, __hostFunction_NativeAsyncStorageSpecJSI_getAllKeys};
657+
methodMap_["getAllKeys"] = MethodMetadata {1, __hostFunction_NativeAsyncLocalStorageSpecJSI_getAllKeys};
658+
659+
}
660+
} // namespace react
661+
} // namespace facebook
662+
663+
namespace facebook {
664+
namespace react {
665+
666+
static facebook::jsi::Value __hostFunction_NativeAsyncSQLiteDBStorageSpecJSI_multiGet(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
667+
return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, VoidKind, "multiGet", @selector(multiGet:callback:), args, count);
668+
}
669+
670+
static facebook::jsi::Value __hostFunction_NativeAsyncSQLiteDBStorageSpecJSI_multiSet(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
671+
return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, VoidKind, "multiSet", @selector(multiSet:callback:), args, count);
672+
}
673+
674+
static facebook::jsi::Value __hostFunction_NativeAsyncSQLiteDBStorageSpecJSI_multiMerge(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
675+
return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, VoidKind, "multiMerge", @selector(multiMerge:callback:), args, count);
676+
}
677+
678+
static facebook::jsi::Value __hostFunction_NativeAsyncSQLiteDBStorageSpecJSI_multiRemove(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
679+
return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, VoidKind, "multiRemove", @selector(multiRemove:callback:), args, count);
680+
}
681+
682+
static facebook::jsi::Value __hostFunction_NativeAsyncSQLiteDBStorageSpecJSI_clear(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
683+
return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, VoidKind, "clear", @selector(clear:), args, count);
684+
}
685+
686+
static facebook::jsi::Value __hostFunction_NativeAsyncSQLiteDBStorageSpecJSI_getAllKeys(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
687+
return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, VoidKind, "getAllKeys", @selector(getAllKeys:), args, count);
688+
}
689+
690+
NativeAsyncSQLiteDBStorageSpecJSI::NativeAsyncSQLiteDBStorageSpecJSI(const ObjCTurboModule::InitParams &params)
691+
: ObjCTurboModule(params) {
692+
693+
methodMap_["multiGet"] = MethodMetadata {2, __hostFunction_NativeAsyncSQLiteDBStorageSpecJSI_multiGet};
694+
695+
696+
methodMap_["multiSet"] = MethodMetadata {2, __hostFunction_NativeAsyncSQLiteDBStorageSpecJSI_multiSet};
697+
698+
699+
methodMap_["multiMerge"] = MethodMetadata {2, __hostFunction_NativeAsyncSQLiteDBStorageSpecJSI_multiMerge};
700+
701+
702+
methodMap_["multiRemove"] = MethodMetadata {2, __hostFunction_NativeAsyncSQLiteDBStorageSpecJSI_multiRemove};
703+
704+
705+
methodMap_["clear"] = MethodMetadata {1, __hostFunction_NativeAsyncSQLiteDBStorageSpecJSI_clear};
706+
707+
708+
methodMap_["getAllKeys"] = MethodMetadata {1, __hostFunction_NativeAsyncSQLiteDBStorageSpecJSI_getAllKeys};
658709

659710
}
660711
} // namespace react

Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec.h

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ namespace facebook {
425425
} // namespace react
426426
} // namespace facebook
427427

428-
@protocol NativeAsyncStorageSpec <RCTBridgeModule, RCTTurboModule>
428+
@protocol NativeAsyncLocalStorageSpec <RCTBridgeModule, RCTTurboModule>
429429

430430
- (void)multiGet:(NSArray *)keys
431431
callback:(RCTResponseSenderBlock)callback;
@@ -442,11 +442,37 @@ namespace facebook {
442442
namespace facebook {
443443
namespace react {
444444
/**
445-
* ObjC++ class for module 'AsyncStorage'
445+
* ObjC++ class for module 'AsyncLocalStorage'
446446
*/
447-
class JSI_EXPORT NativeAsyncStorageSpecJSI : public ObjCTurboModule {
447+
class JSI_EXPORT NativeAsyncLocalStorageSpecJSI : public ObjCTurboModule {
448448
public:
449-
NativeAsyncStorageSpecJSI(const ObjCTurboModule::InitParams &params);
449+
NativeAsyncLocalStorageSpecJSI(const ObjCTurboModule::InitParams &params);
450+
};
451+
} // namespace react
452+
} // namespace facebook
453+
454+
@protocol NativeAsyncSQLiteDBStorageSpec <RCTBridgeModule, RCTTurboModule>
455+
456+
- (void)multiGet:(NSArray *)keys
457+
callback:(RCTResponseSenderBlock)callback;
458+
- (void)multiSet:(NSArray *)kvPairs
459+
callback:(RCTResponseSenderBlock)callback;
460+
- (void)multiMerge:(NSArray *)kvPairs
461+
callback:(RCTResponseSenderBlock)callback;
462+
- (void)multiRemove:(NSArray *)keys
463+
callback:(RCTResponseSenderBlock)callback;
464+
- (void)clear:(RCTResponseSenderBlock)callback;
465+
- (void)getAllKeys:(RCTResponseSenderBlock)callback;
466+
467+
@end
468+
namespace facebook {
469+
namespace react {
470+
/**
471+
* ObjC++ class for module 'AsyncSQLiteDBStorage'
472+
*/
473+
class JSI_EXPORT NativeAsyncSQLiteDBStorageSpecJSI : public ObjCTurboModule {
474+
public:
475+
NativeAsyncSQLiteDBStorageSpecJSI(const ObjCTurboModule::InitParams &params);
450476
};
451477
} // namespace react
452478
} // namespace facebook
@@ -2488,6 +2514,7 @@ inline JS::NativeAppState::Constants::Builder::Builder(Constants i) : _factory(^
24882514
}) {}
24892515

24902516

2517+
24912518
inline JS::NativeBlobModule::Constants::Builder::Builder(const Input i) : _factory(^{
24922519
NSMutableDictionary *d = [NSMutableDictionary new];
24932520
auto BLOB_URI_SCHEME = i.BLOB_URI_SCHEME.get();

Libraries/Storage/AsyncStorage.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212

1313
'use strict';
1414

15-
import NativeAsyncStorage from './NativeAsyncStorage';
15+
import NativeAsyncLocalStorage from './NativeAsyncLocalStorage';
16+
import NativeAsyncSQLiteDBStorage from './NativeAsyncSQLiteDBStorage';
1617
import invariant from 'invariant';
1718

1819
// Use SQLite if available, otherwise file storage.
19-
const RCTAsyncStorage = NativeAsyncStorage;
20+
const RCTAsyncStorage = NativeAsyncSQLiteDBStorage || NativeAsyncLocalStorage;
2021

2122
/**
2223
* `AsyncStorage` is a simple, unencrypted, asynchronous, persistent, key-value
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow strict
8+
* @format
9+
*/
10+
11+
'use strict';
12+
13+
import type {TurboModule} from '../TurboModule/RCTExport';
14+
import * as TurboModuleRegistry from '../TurboModule/TurboModuleRegistry';
15+
16+
export interface Spec extends TurboModule {
17+
+getConstants: () => {||};
18+
+multiGet: (
19+
keys: Array<string>,
20+
callback: (
21+
errors: ?Array<{|message: string|}>,
22+
kvPairs: ?Array<Array<string>>,
23+
) => void,
24+
) => void;
25+
+multiSet: (
26+
kvPairs: Array<Array<string>>,
27+
callback: (errors: ?Array<{|message: string|}>) => void,
28+
) => void;
29+
+multiMerge: (
30+
kvPairs: Array<Array<string>>,
31+
callback: (errors: ?Array<{|message: string|}>) => void,
32+
) => void;
33+
+multiRemove: (
34+
keys: Array<string>,
35+
callback: (errors: ?Array<{|message: string|}>) => void,
36+
) => void;
37+
+clear: (callback: (error: {|message: string|}) => void) => void;
38+
+getAllKeys: (
39+
callback: (error: ?{|message: string|}, allKeys: ?Array<string>) => void,
40+
) => void;
41+
}
42+
43+
export default (TurboModuleRegistry.get<Spec>('AsyncLocalStorage'): ?Spec);

Libraries/Storage/NativeAsyncStorage.js renamed to Libraries/Storage/NativeAsyncSQLiteDBStorage.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,4 @@ export interface Spec extends TurboModule {
4040
) => void;
4141
}
4242

43-
export default (TurboModuleRegistry.get<Spec>('AsyncSQLiteDBStorage') ||
44-
TurboModuleRegistry.get<Spec>('AsyncLocalStorage'): ?Spec);
43+
export default (TurboModuleRegistry.get<Spec>('AsyncSQLiteDBStorage'): ?Spec);

React/CoreModules/RCTAsyncLocalStorage.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ static dispatch_queue_t RCTGetMethodQueue()
162162

163163
#pragma mark - RCTAsyncLocalStorage
164164

165-
@interface RCTAsyncLocalStorage () <NativeAsyncStorageSpec>
165+
@interface RCTAsyncLocalStorage () <NativeAsyncLocalStorageSpec>
166166
@end
167167

168168
@implementation RCTAsyncLocalStorage {
@@ -455,7 +455,7 @@ - (NSDictionary *)_writeEntry:(NSArray<NSString *> *)entry changedManifest:(BOOL
455455
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
456456
(const facebook::react::ObjCTurboModule::InitParams &)params
457457
{
458-
return std::make_shared<facebook::react::NativeAsyncStorageSpecJSI>(params);
458+
return std::make_shared<facebook::react::NativeAsyncLocalStorageSpecJSI>(params);
459459
}
460460

461461
@end

ReactAndroid/src/main/java/com/facebook/fbreact/specs/NativeAsyncStorageSpec.java renamed to ReactAndroid/src/main/java/com/facebook/fbreact/specs/NativeAsyncLocalStorageSpec.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
import com.facebook.react.bridge.ReadableArray;
2121
import com.facebook.react.turbomodule.core.interfaces.TurboModule;
2222

23-
public abstract class NativeAsyncStorageSpec extends ReactContextBaseJavaModule implements ReactModuleWithSpec, TurboModule {
24-
public NativeAsyncStorageSpec(ReactApplicationContext reactContext) {
23+
public abstract class NativeAsyncLocalStorageSpec extends ReactContextBaseJavaModule implements ReactModuleWithSpec, TurboModule {
24+
public NativeAsyncLocalStorageSpec(ReactApplicationContext reactContext) {
2525
super(reactContext);
2626
}
2727

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* <p>This source code is licensed under the MIT license found in the LICENSE file in the root
5+
* directory of this source tree.
6+
*
7+
* <p>Generated by an internal genrule from Flow types.
8+
*
9+
* @generated
10+
* @nolint
11+
*/
12+
13+
package com.facebook.fbreact.specs;
14+
15+
import com.facebook.react.bridge.Callback;
16+
import com.facebook.react.bridge.ReactApplicationContext;
17+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
18+
import com.facebook.react.bridge.ReactMethod;
19+
import com.facebook.react.bridge.ReactModuleWithSpec;
20+
import com.facebook.react.bridge.ReadableArray;
21+
import com.facebook.react.turbomodule.core.interfaces.TurboModule;
22+
23+
public abstract class NativeAsyncSQLiteDBStorageSpec extends ReactContextBaseJavaModule implements ReactModuleWithSpec, TurboModule {
24+
public NativeAsyncSQLiteDBStorageSpec(ReactApplicationContext reactContext) {
25+
super(reactContext);
26+
}
27+
28+
@ReactMethod
29+
public abstract void clear(Callback callback);
30+
31+
@ReactMethod
32+
public abstract void getAllKeys(Callback callback);
33+
34+
@ReactMethod
35+
public abstract void multiGet(ReadableArray keys, Callback callback);
36+
37+
@ReactMethod
38+
public abstract void multiMerge(ReadableArray kvPairs, Callback callback);
39+
40+
@ReactMethod
41+
public abstract void multiRemove(ReadableArray keys, Callback callback);
42+
43+
@ReactMethod
44+
public abstract void multiSet(ReadableArray kvPairs, Callback callback);
45+
}

0 commit comments

Comments
 (0)