Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(mmkv): remove async storage pkg #153

Merged
merged 6 commits into from
Mar 28, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(mmkv): remove async storage pkg
  • Loading branch information
frankcalise committed Mar 28, 2024
commit c110f32a2a0126fae0bcdbd402e8789148b0bc62
81 changes: 41 additions & 40 deletions docs/recipes/MigratingToMMKV.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ cd PizzaApp
Install the `react-native-mmkv` dependency into the project and run prebuild again to let Expo take care of the necessary adjustments to the native template.

```bash
yarn remove @react-native-async-storage/async-storage
yarn add react-native-mmkv
yarn prebuild
```
Expand Down Expand Up @@ -177,68 +178,68 @@ Now that you've moved the base storage functions over to MMKV, you might want to
You may notice that the `storage.test.ts` test file will no longer pass. Replace the contents of this file with the following test data:

```tsx
import { load, loadString, save, saveString, clear, remove } from "./storage"
import { storage } from "./mmkv" // <- wherever your global `new MMKV()` constant is
import { load, loadString, save, saveString, clear, remove } from "./storage";
Copy link
Contributor

Choose a reason for hiding this comment

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

Are the addition of semicolons intended? No opinion either way, just wanted to check since it wasn't mentioned

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably an auto format thing, I'll double check with the consistency of the other snippets. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Going to leave it alone, seems as if the other recipes have it via the formatter.

import { storage } from "./mmkv"; // <- wherever your global `new MMKV()` constant is

const VALUE_OBJECT = { x: 1 }
const VALUE_STRING = JSON.stringify(VALUE_OBJECT)
const VALUE_OBJECT = { x: 1 };
const VALUE_STRING = JSON.stringify(VALUE_OBJECT);

describe("MMKV Storage", () => {
beforeEach(() => {
storage.clearAll()
storage.set("string", "string")
storage.set("object", JSON.stringify(VALUE_OBJECT))
})
storage.clearAll();
storage.set("string", "string");
storage.set("object", JSON.stringify(VALUE_OBJECT));
});

it("should be defined", () => {
expect(storage).toBeDefined()
})
expect(storage).toBeDefined();
});

it("should have default keys", () => {
expect(storage.getAllKeys()).toEqual(["string", "object"])
})
expect(storage.getAllKeys()).toEqual(["string", "object"]);
});

it("should load data", () => {
expect(load("object")).toEqual(VALUE_OBJECT)
expect(loadString("object")).toEqual(VALUE_STRING)
expect(load("object")).toEqual(VALUE_OBJECT);
expect(loadString("object")).toEqual(VALUE_STRING);

expect(load("string")).toEqual("string")
expect(loadString("string")).toEqual("string")
})
expect(load("string")).toEqual("string");
expect(loadString("string")).toEqual("string");
});

it("should save strings", () => {
saveString("string", "new string")
expect(loadString("string")).toEqual("new string")
})
saveString("string", "new string");
expect(loadString("string")).toEqual("new string");
});

it("should save objects", () => {
save("object", { y: 2 })
expect(load("object")).toEqual({ y: 2 })
save("object", { z: 3, also: true })
expect(load("object")).toEqual({ z: 3, also: true })
})
save("object", { y: 2 });
expect(load("object")).toEqual({ y: 2 });
save("object", { z: 3, also: true });
expect(load("object")).toEqual({ z: 3, also: true });
});

it("should save strings and objects", () => {
saveString("object", "new string")
expect(loadString("object")).toEqual("new string")
})
saveString("object", "new string");
expect(loadString("object")).toEqual("new string");
});

it("should remove data", () => {
remove("object")
expect(load("object")).toBeUndefined()
expect(storage.getAllKeys()).toEqual(["string"])
remove("object");
expect(load("object")).toBeUndefined();
expect(storage.getAllKeys()).toEqual(["string"]);

remove("string")
expect(load("string")).toBeUndefined()
expect(storage.getAllKeys()).toEqual([])
})
remove("string");
expect(load("string")).toBeUndefined();
expect(storage.getAllKeys()).toEqual([]);
});

it("should clear all data", () => {
expect(storage.getAllKeys()).toEqual(["string", "object"])
clear()
expect(storage.getAllKeys()).toEqual([])
})
})
expect(storage.getAllKeys()).toEqual(["string", "object"]);
clear();
expect(storage.getAllKeys()).toEqual([]);
});
});
```

Run the app in the iOS simulator to test the changes with `yarn ios`. Navigate to the Podcast List screen:
Expand Down
Loading