Page MenuHomePhabricator

[native] Introduce a hook that allows running an effect just once per installation
ClosedPublic

Authored by tomek on May 9 2023, 2:53 AM.
Tags
None
Referenced Files
F3387412: D7751.diff
Fri, Nov 29, 9:22 AM
Unknown Object (File)
Tue, Nov 26, 3:31 AM
Unknown Object (File)
Oct 28 2024, 1:26 AM
Unknown Object (File)
Oct 28 2024, 1:26 AM
Unknown Object (File)
Oct 28 2024, 1:26 AM
Unknown Object (File)
Oct 28 2024, 1:26 AM
Unknown Object (File)
Oct 28 2024, 1:18 AM
Unknown Object (File)
Sep 28 2024, 5:19 AM
Subscribers

Details

Summary

When checking referrer on Android, we would like to do it at most once per installation. To achieve that we can set a value in AsyncStorage and run the effect only if the value is not set.

Depends on D7743

Test Plan

Tested in combination with the next diff. Install the app using the referrer on Android, open the app and cancel invitation, close and open the app - the invitation shouldn't appear again.

Diff Detail

Repository
rCOMM Comm
Lint
No Lint Coverage
Unit
No Test Coverage

Event Timeline

tomek requested review of this revision.May 9 2023, 3:11 AM
This revision is now accepted and ready to land.May 9 2023, 4:42 AM
native/utils/hooks.js
9

There is no guarantee here that this will only execute once.

  1. Is that potentially concerning in your use case? Or is your use case "idempotent", meaning it's okay for it to happen multiple times, but would be preferred to happen only once?
  2. If it is not concerning in your use case, we should consider that you are introducing a utility that others might consume in the future. You should add a code comment clarifying that effect should be idempotent, and the caller should be okay with it potentially be called more than once if effect is ever changed.
native/utils/hooks.js
9

In this case the effect is about displaying invitation modal. So displaying it twice should be avoided but isn't a huge issue. I'm going to add comments that explain that it's possible for an effect to run multiple times.

I can also spend some time thinking about making this safer.

Make the logic a lot safer.

native/utils/hooks.js
9

I modified the logic so that now it's extremely unlikely that an effect might run twice - the only serious case is when saving to async storage fails - then the next run of the app will result in running the effect again.

Thanks, this is much safer!

native/utils/hooks.js
21 ↗(On Diff #26449)

I guess it's safe to call await on something that isn't a promise?

native/utils/hooks.js
21 ↗(On Diff #26449)