-
Notifications
You must be signed in to change notification settings - Fork 759
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
Use EventTarget in worker / browser runtimes #1668
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
anniel-stripe
commented
Jan 31, 2023
anniel-stripe
force-pushed
the
anniel-eventtarget
branch
2 times, most recently
from
January 31, 2023 18:25
0b9ad42
to
7507881
Compare
anniel-stripe
force-pushed
the
anniel-eventtarget
branch
from
January 31, 2023 18:29
7507881
to
6834c56
Compare
pakrym-stripe
requested changes
Jan 31, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Let's refactor platform functions a bit so we don't have to push more logic into entry point.
- Let's add some tests to confirm parity between event emitter implementations.
- Let's decide what we want to do with file streams in non-node environments.
anniel-stripe
force-pushed
the
anniel-eventtarget
branch
from
January 31, 2023 19:28
68b6119
to
c51ee5f
Compare
anniel-stripe
force-pushed
the
anniel-eventtarget
branch
from
February 1, 2023 06:27
4047a2d
to
fc725cd
Compare
anniel-stripe
commented
Feb 1, 2023
anniel-stripe
commented
Feb 1, 2023
anniel-stripe
force-pushed
the
anniel-eventtarget
branch
from
February 1, 2023 19:13
bd05820
to
a4de0a8
Compare
pakrym-stripe
requested changes
Feb 1, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
few more nits
Co-authored-by: pakrym-stripe <[email protected]>
pakrym-stripe
approved these changes
Feb 1, 2023
pakrym-stripe
approved these changes
Feb 1, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
_emitter
property on theStripe
object to useEventTarget
instead ofEventEmitter
in worker environments.PlatformFunctions
that is implemented byWebPlatformFunctions
andNodePlatformFunctions
tryBufferData
platform function, which throws an error in workers if aReadableStream
is detected.Workarounds because of Node <15
Event
andEventTarget
are only available in the global scope starting with Node 14. Since_StripeEvent
needs to extendEvent
(to add thedata
object used by listener functions), I ended up creating a base class forPlatformFunctions
and a separateWebPlatformFunctions
that is the only place whereStripeEmitter
is imported.In the tests I added to
PlatformFunctions.spec.ts
, I also added a check for the Node version so thatWebPlatformFunctions
test do not run in Node <= 14.Testing
This gets rid of the last of the build errors when importing stripe-node in Cloudflare Workers without polyfills. I tested this new implementation in Cloudflare Workers / Pages and both emit events as expected.