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

Implemented multi-init guard #17

Merged
merged 2 commits into from
Feb 16, 2021
Merged

Implemented multi-init guard #17

merged 2 commits into from
Feb 16, 2021

Conversation

hkan
Copy link
Contributor

@hkan hkan commented Feb 8, 2021

There is an issue when developing React Native apps that have deepwall-react-native-sdk package installed.

Imagine a RN app that has Deepwall properly set up, and has a listener for a Deepwall event as such:

DeepWallEventBus.getInstance().addListener(DeepWallEvents.PAYWALL_OPENED, this.paywallOpenedListener = data => {
    console.log('paywall opened');
});

What a developer would see in their terminal when the app is starting is a string saying paywall opened. When the developer makes a change on the app's Javascript codes and saves the file, the app reloads to reflect the changes. What that developer now sees in their terminal when the app is reloading is two new strings saying paywall opened.

The reason the event listeners getting called twice is because on the reload action, the underlying native app does not actually restart. Only the Javascript part restarts. Every time JS part restarts, it calls the initDeepwall() function to start Deepwall's functionalities, but on recurring reloads of the JS part the Deepwall is already initiated. See the simple scenario below for alternative explanation.

  • Developer builds and starts the app on a simulator or a device.
  • Phone starts the underlying native app.
  • Native app starts JS app.
  • JS app calls initDeepwall().
  • Native app initializes Deepwall.
  • At this point app is fully loaded and ready to use.
  • Developer makes a change on some part of the code.
  • Native app reloads JS app.
  • At this point Deepwall is still intact and already initialized, because the native app did not restart.
  • JS app calls initDeepwall().
  • Native app initializes Deepwall AGAIN.
  • At this point any event listeners will be triggered twice for each occurrence.

This PR introduces a simple boolean flag and a guard check to fix that problem.

@hkan
Copy link
Contributor Author

hkan commented Feb 15, 2021

Any updates on this?

@semiherdogan semiherdogan self-assigned this Feb 15, 2021
@semiherdogan
Copy link
Collaborator

Hi @hkan
Thanks for the pr, we are testing these changes.
We will merge this soon.

@semiherdogan semiherdogan merged commit 4932158 into Teknasyon-Teknoloji:master Feb 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants