-
Notifications
You must be signed in to change notification settings - Fork 197
add saveDelay option for persistor #811
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
Conversation
Hi @ku8ar , this is a good thing to have it exposed as an option in the client. Thanks for the suggestion. I think it would be worth passing it on the rest of the storages, in particular the |
hi @oscb , thank you for your quick response. I have added saveDelay in the rest of the places. |
@ku8ar thanks so much! lgtm |
@ku8ar this is failing to run because the types here and here are |
hey. I completely forgot about your comment. Sorry. I just fixed the types. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm! Thanks for the contribution!
## [@segment/analytics-react-native-v2.16.0](https://github.com/segmentio/analytics-react-native/compare/@segment/analytics-react-native-v2.15.0...@segment/analytics-react-native-v2.16.0) (2023-08-21) ### Features * add saveDelay option for persistor ([#811](#811)) ([11d5e87](11d5e87)) ### Bug Fixes * package dependency fixes ([#869](#869)) ([08d415e](08d415e)) * resolve potential build issues with RN 0.72 ([#841](#841)) ([d287304](d287304))
🎉 This PR is included in version @segment/analytics-react-native-v2.16.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Hi @ku8ar, I was curious if you could provide an example of making this work with MMKV. I've tried adding the MMKV storage to storePersistor:
Where However, it's not working and of course, I am getting type errors where the methods don't align. How did you go about integrating this? Really appreciate it. |
@thianphat just create simple persistor and write everything as JSON: import { isNil } from 'ramda'
import { MMKV } from 'react-native-mmkv'
const storage = new MMKV({ id: 'segment' })
const storePersistor = {
set: (key, value) => {
storage.set(key, JSON.stringify(value))
},
get: (key) => {
const mmkvValue = storage.getString(key)
if (!isNil(mmkvValue)) {
return JSON.parse(mmkvValue)
}
}
}
export default storePersistor |
We use MMKV to save the events. We don't need default 1s delay. Such config logs fewer events (when the user kills the app quickly)