Skip to content

Commit

Permalink
fix: filter out storage key
Browse files Browse the repository at this point in the history
  • Loading branch information
ammarahm-ed committed Nov 25, 2023
1 parent 5170777 commit f5b014c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
1 change: 0 additions & 1 deletion android/src/main/rnmmkv/rnmmkv-adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,6 @@ void initIndexForId(std::string id)

void installBindings(Runtime &jsiRuntime)
{
;

CREATE_FUNCTION("initializeMMKV", 0, {
MMKV::initializeMMKV(rPath);
Expand Down
10 changes: 10 additions & 0 deletions example/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ const App = () => {
storage.clearStore();
},
},
{
title: 'removeByKeys',
onPress: async () => {
const keys = await storage.indexer.getKeys();
console.log(keys);
storage.removeItems(keys);
storage.clearStore();
console.log(await storage.indexer.getKeys());
},
},
];

return (
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-mmkv-storage",
"version": "0.10.0-alpha.10",
"version": "0.10.0-alpha.11",
"description": "This library aims to provide a fast & reliable solution for you data storage needs in react-native apps. It uses [MMKV](https://github.com/Tencent/MMKV) by Tencent under the hood on Android and iOS both that is used by their WeChat app(more than 1 Billion users). Unlike other storage solutions for React Native, this library lets you store any kind of data type, in any number of database instances, with or without encryption in a very fast and efficient way.",
"main": "./dist/index.js",
"scripts": {
Expand Down
9 changes: 7 additions & 2 deletions src/mmkvinstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -609,8 +609,12 @@ export default class MMKVInstance {
* Remove multiple items from storage for given keys
*
*/
removeItems(...keys: string[]) {
let result = handleAction(mmkvJsiModule.removeValuesMMKV, keys, this.instanceID);
removeItems(keys: string[]) {
let result = handleAction(
mmkvJsiModule.removeValuesMMKV,
keys.filter(key => key !== this.instanceID),
this.instanceID
);
for (const key of keys) {
if (result) {
if (this.isRegisterd(key)) {
Expand All @@ -621,6 +625,7 @@ export default class MMKVInstance {
this.transactions.transact('string', 'ondelete', key);
}
}

return result;
}

Expand Down

1 comment on commit f5b014c

@vercel
Copy link

@vercel vercel bot commented on f5b014c Nov 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

rnmmkv – ./

rnmmkv-ammarahm-ed.vercel.app
rnmmkv.vercel.app
rnmmkv-git-master-ammarahm-ed.vercel.app

Please sign in to comment.