From 7b8235a95ad9519e9735cc1555a8d3aa5bb7c0ee Mon Sep 17 00:00:00 2001 From: Teddy Martin Date: Tue, 29 Jan 2019 08:41:04 -0800 Subject: [PATCH] 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. Pull Request resolved: https://github.com/facebook/react-native/pull/18454 Differential Revision: D13860333 Pulled By: cpojer fbshipit-source-id: b33ee5bf1ec65c8291bfcb76b0d6f0df39376a7e --- React/Modules/RCTAsyncLocalStorage.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/React/Modules/RCTAsyncLocalStorage.h b/React/Modules/RCTAsyncLocalStorage.h index 386f9f5ed99e87..f079484a66c5c6 100644 --- a/React/Modules/RCTAsyncLocalStorage.h +++ b/React/Modules/RCTAsyncLocalStorage.h @@ -31,4 +31,11 @@ // For clearing data when the bridge may not exist, e.g. when logging out. + (void)clearAllData; +// 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 *)keys callback:(RCTResponseSenderBlock)callback; + +// Add multiple key value pairs to the cache. +- (void)multiSet:(NSArray *> *)kvPairs callback:(RCTResponseSenderBlock)callback; + + @end