Skip to content

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

Merged
merged 6 commits into from
Jul 6, 2023
Merged

add saveDelay option for persistor #811

merged 6 commits into from
Jul 6, 2023

Conversation

ku8ar
Copy link
Contributor

@ku8ar ku8ar commented Apr 12, 2023

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)

@oscb
Copy link
Contributor

oscb commented Apr 12, 2023

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 userInfoStore as events can have side effects on those which should also be persisted quickly in your scenario.

@ku8ar
Copy link
Contributor Author

ku8ar commented Apr 13, 2023

hi @oscb , thank you for your quick response. I have added saveDelay in the rest of the places.

@oscb
Copy link
Contributor

oscb commented Apr 13, 2023

@ku8ar thanks so much! lgtm

@oscb
Copy link
Contributor

oscb commented May 3, 2023

@ku8ar this is failing to run because the types here and here are Number (which is a class type in TS) where it should be number (which is primitive).
Since this is coming from a fork I wasn't able to edit the PR directly. If you can do that I can approve this PR and merge, or I can make another PR with your changes and that fix if that's easier.

@ku8ar
Copy link
Contributor Author

ku8ar commented May 22, 2023

hey. I completely forgot about your comment. Sorry. I just fixed the types.

Copy link
Contributor

@oscb oscb left a 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!

@oscb oscb merged commit 11d5e87 into segmentio:master Jul 6, 2023
oscb pushed a commit that referenced this pull request Aug 21, 2023
## [@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))
@oscb
Copy link
Contributor

oscb commented Aug 21, 2023

🎉 This PR is included in version @segment/analytics-react-native-v2.16.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@oscb oscb added the released label Aug 21, 2023
@thianphat
Copy link

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:

storePersistor: storage

Where storage is equal to new MMKV()

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.

@ku8ar
Copy link
Contributor Author

ku8ar commented Mar 25, 2024

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants