diff --git a/packages/rn-async-storage-flipper/index.js b/packages/rn-async-storage-flipper/index.js index f6e38a0..14ba89f 100644 --- a/packages/rn-async-storage-flipper/index.js +++ b/packages/rn-async-storage-flipper/index.js @@ -17,6 +17,35 @@ function ReactNativeAsyncStorageFlipper(storage) { bootstrapPlugin() .then((currentConnection) => { if (currentConnection) { + const setItem = storage.setItem; + const removeItem = storage.removeItem; + + storage.setItem = (key, value, ...rest) => { + setItem(key, value, ...rest); + + let sendValue = value; + let needsToBeParsed = (sendValue.startsWith('{') && sendValue.endsWith('}')) || (sendValue.startsWith('[') && sendValue.endsWith(']')); + + if (needsToBeParsed) { + sendValue = JSON.parse(sendValue); + } + + currentConnection.send('newElement', { + key, + value: sendValue, + id: key, + }); + }; + + storage.removeItem = (key, ...rest) => { + removeItem(key, ...rest); + currentConnection.send('newElement', { + key, + value: null, + id: key, + }); + }; + storage.getAllKeys().then((keys) => { storage.multiGet(keys).then((data) => { data.map((_, i, store) => {