react-native-macos/React/Modules/RCTAsyncLocalStorage.h

42 строки
1.5 KiB
C
Исходник Обычный вид История

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <React/RCTBridgeModule.h>
#import <React/RCTInvalidating.h>
/**
* A simple, asynchronous, persistent, key-value storage system designed as a
* backend to the AsyncStorage JS module, which is modeled after LocalStorage.
*
* Current implementation stores small values in serialized dictionary and
* larger values in separate files. Since we use a serial file queue
* `RKFileQueue`, reading/writing from multiple threads should be perceived as
* being atomic, unless someone bypasses the `RCTAsyncLocalStorage` API.
*
* Keys and values must always be strings or an error is returned.
*/
2015-06-18 19:29:31 +03:00
@interface RCTAsyncLocalStorage : NSObject <RCTBridgeModule,RCTInvalidating>
@property (nonatomic, assign) BOOL clearOnInvalidate;
@property (nonatomic, readonly, getter=isValid) BOOL valid;
// Clear the RCTAsyncLocalStorage data from native code
- (void)clearAllData;
2015-06-18 19:29:31 +03:00
// For clearing data when the bridge may not exist, e.g. when logging out.
2015-06-23 00:37:11 +03:00
+ (void)clearAllData;
2015-06-18 19:29:31 +03:00
Expose AsyncLocalStorage get/set methods (#18454) Summary: Currently, if an app uses AsyncStorage on the JS side, there is no public interface to access stored data from the native side. In our app, written in Swift, I have written a [helper](https://gist.github.com/ejmartin504/d501abe55c28450a0e52ac39aee7b0e6) that pulls out the data. I accomplished this by reverse-engineering the code in RCTAsyncLocalStorage.m. It would have been far easier had this code been exposed to native. I made this change locally and tested out getting the data from Swift code. This worked like a charm: ```swift let storage = RCTAsyncLocalStorage() let cacheKey = "test" storage.methodQueue?.async { self.storage.multiGet([cacheKey]) { values in print(values) } } ``` [IOS ][ENHANCEMENT ][RCTAsyncLocalStorage.h] - Expose AsyncLocalStorage get/set methods to native code. <!-- **INTERNAL and MINOR tagged notes will not be included in the next version's final release notes.** CATEGORY [----------] TYPE [ CLI ] [-------------] LOCATION [ DOCS ] [ BREAKING ] [-------------] [ GENERAL ] [ BUGFIX ] [ {Component} ] [ INTERNAL ] [ ENHANCEMENT ] [ {Filename} ] [ IOS ] [ FEATURE ] [ {Directory} ] |-----------| [ ANDROID ] [ MINOR ] [ {Framework} ] - | {Message} | [----------] [-------------] [-------------] |-----------| EXAMPLES: [IOS] [BREAKING] [FlatList] - Change a thing that breaks other things [ANDROID] [BUGFIX] [TextInput] - Did a thing to TextInput [CLI] [FEATURE] [local-cli/info/info.js] - CLI easier to do things with [DOCS] [BUGFIX] [GettingStarted.md] - Accidentally a thing/word [GENERAL] [ENHANCEMENT] [Yoga] - Added new yoga thing/position [INTERNAL] [FEATURE] [./scripts] - Added thing to script that nobody will see --> Pull Request resolved: https://github.com/facebook/react-native/pull/18454 Differential Revision: D13860333 Pulled By: cpojer fbshipit-source-id: b33ee5bf1ec65c8291bfcb76b0d6f0df39376a7e
2019-01-29 19:41:04 +03:00
// Grab data from the cache. ResponseBlock result array will have an error at position 0, and an array of arrays at position 1.
- (void)multiGet:(NSArray<NSString *> *)keys callback:(RCTResponseSenderBlock)callback;
// Add multiple key value pairs to the cache.
- (void)multiSet:(NSArray<NSArray<NSString *> *> *)kvPairs callback:(RCTResponseSenderBlock)callback;
@end