Skip to content

Commit

Permalink
feat: Merge pull request #14 from lucasfeijo/patch-1
Browse files Browse the repository at this point in the history
BREAKING CHANGE: on Android, `enforceSingleInvocation` is true by default
  • Loading branch information
doomsower committed Apr 25, 2021
2 parents efdf4d4 + 947fc8c commit 42a718e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 22 deletions.
39 changes: 18 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@ If you know a better way to measure startup time (in a module), let me know or b

### Mostly automatic installation

This module supports autolinking so if you use RN 0.60+ then no additional action is required.
This module supports autolinking so **if you use RN 0.60+ then no additional action is required**.

Otherwise, run

`$ react-native link react-native-startup-time`

### Manual linking installation

<details>
<summary>Show manual installation steps</summary>

1. Open `./android/settings.gradle`, add this:

```gradle
Expand All @@ -44,20 +47,20 @@ import com.github.doomsower.RNStartupTimePackage;
// Define package
new RNStartupTimePackage()
```
</details>


## Usage

Render startup time badge somewhere on your first screen:

```jsx
import { StartupTime } from 'react-native-startup-time';
...

<StartupTime
ready={true /* optional, defaults to true */}
style={styles.startupTime /* optional*/}
ready={true /* optional, defaults to true */}
style={styles.startupTime /* optional*/}
/>

```

Or use imperative call:
Expand All @@ -71,26 +74,20 @@ getTimeSinceStartup().then((time) => {
});
```

### Ensuring purity of your analytics data
_The following sections are applicable to Android only_

### Single-Sampling

This makes sure Android doesn't resolve the getTimeSinceStartup promise more than once per app execution. More information in [PR #10](https://github.com/doomsower/react-native-startup-time/pull/10).

_This section is applicable to Android only_
Since v1.4.0 this strategy is enabled by default, if you're migrating from a previous version and you just want things to keep working as they are, follow the steps below.

In case you're going to use this library for collecting the performance analytics, be aware to discard redundant samples which may sometimes pop up.
#### Disabling Single-Sampling:

Depending on which lifecycle hook you've attached your call to `getTimeSinceStartup()` you might receive redundant invocations, e.g. when the app is brought from bg to fg. Because the app isn't really starting up, the measured time can be unrealistic; such unrealistic samples adulterate your data and should be avoided.
Be aware, depending on which lifecycle hook you've attached your call to `getTimeSinceStartup()` you might receive redundant invocations, e.g. when the app is brought from bg to fg. Because the app isn't really starting up, the measured time can be unrealistic; such unrealistic samples adulterate your data.

To enforce single-sampling strategy, create your package using constructor with parameter `true`:
To disable single-sampling strategy, create your package using constructor with parameter `false`:
```java
// Define package
new RNStartupTimePackage(true)
new RNStartupTimePackage(false)
```
then sample the startup time with catching the redundant invocation error:
```jsx
// when you app is ready:
getTimeSinceStartup().then((time) => {
// Initial sample. Collect it for your analytics.
})
.catch((e) => {
// Redundant sample. Do nothing or print a log.
});
```
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class RNStartupTimePackage implements ReactPackage {
private boolean enforceSingleInvocation;

public RNStartupTimePackage() {
this(false);
this(true);
}

/**
Expand Down

0 comments on commit 42a718e

Please sign in to comment.