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

chore: Add react-native EventSource #318

Merged
merged 11 commits into from
Nov 28, 2023
Merged

Conversation

yusinto
Copy link
Contributor

@yusinto yusinto commented Nov 20, 2023

This adds a local customised copy of react-native-sse. I have modified this to be in TypeScript and added minimal extra logic to work with our use case.

Copy link

This pull request has been linked to Shortcut Story #223903: Add RN EventSource.

@@ -0,0 +1,309 @@
/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you comment on the parts in here that had to change? Aside from being converted to typescript.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the idea we would change this to work with our retry model?

One thing I have disliked in our implementation is the retry logic inside the event source. This event source supports disabling retries, so I was curious if we could just do that and use it without modifications. Then have a small layer that just adapts and adds retry/backoff.

This is effectively what we were doing in client side JS, because the browser doesn't support jitter/backoff.

It doesn't have the benefit of being able to disable retry/backoff, so it does it by closing it.
https://github.com/launchdarkly/js-sdk-common/blob/main/src/Stream.js

If you made a WithJitterBackoff implementation, then you could probably use it for react-native and browser.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now due to time constraints, to use whatever retry logic that is originally in the repo without changes. I am trying to get an alpha release that supports streaming in the most rudimentary fashion again in the interest of time.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you comment on the parts in here that had to change?

The idea is to own this code from now and not be concerned with syncing our copy with the original copy. I'm hesitant to maintain a list of changes every time we make changes to this code. I can record what I changed in this PR so we have a record, but to maintain a list every time is unnecessary and burdensome imho.

Copy link
Member

@kinyoklion kinyoklion Nov 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Being as we didn't start with the base version I don't have any focus to review.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok no worries. I added major changes as comments per your request.


import { name, version } from '../package.json';
import { btoa, uuidv4 } from './polyfills';
import { btoa, EventSource as RNEventSource, uuidv4 } from './polyfills';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a little hesitant to call it a polyfill.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not too fussed and will adopt a better term/convention apart from polyfills. Any suggestions?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you were just writing some code to stream events, and it wasn't some feature browsers happened to have, then what would you call it?

I would probably have something like network/event-source or something. I am not too critical right now, but polyfill has implications that I would rather not have longer term.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved the react-native-sse folder out of polyfills so its directly under src for now. Is this ok?

@yusinto yusinto requested a review from kinyoklion November 27, 2023 23:20
This PR makes minor improvements to the StreamingProcessor.
@yusinto yusinto merged commit aaaf6d1 into main Nov 28, 2023
@yusinto yusinto deleted the yus/sc-223903/add-rn-eventsource branch November 28, 2023 00:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants