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

Fix(Structures): XXX cause event XXX to fires twice #3290

Closed
wants to merge 0 commits into from
Closed

Fix(Structures): XXX cause event XXX to fires twice #3290

wants to merge 0 commits into from

Conversation

KhooHaoYit
Copy link
Contributor

@KhooHaoYit KhooHaoYit commented May 22, 2019

Please describe the changes this PR makes and why it should be merged:
This PR fixes similar problems like #3277 and #3252.

.delete() execute an event action handler.
After that, it got executed again by the WebSocketManager.

                Discord.js  Discord API
Call .create()      |            |
 Send API           | ---------> |
                    | <- - - - - | Execute web socket
                    |            |  Emit event
                    |            |   Check (Add)
                    |            |   handle() (Emit)
 Emit event         |            |
  Check (?Add)      |            |
  handle() (?Emit)  |            |
 Return object      |            |
                    | <- - - - - | Execute web socket
                    |            |  Emit event
                    |            |   Check (Exists)
                    |            |   handle()

Call .delete()      |            |
 Send API           | ---------> |
                    | <- - - - - | Execute web socket
                    |            |  Emit event
                    |            |   Check (Add)
                    |            |   handle() (Remove, Emit)
 Emit event         |            |
  Check (?Add)      |            |
  handle() (Remove, |            |
  1st/2nd Emit)     |            |
 Return object      |            |
                    | <- - - - - | Execute web socket
                    |            |  Emit event
                    |            |   Check (Add)
                    |            |   handle() (Remove, 2nd Emit)

Problem: The 2nd event emit is come from the .delete() or web socket.
The reason the 2nd event emits is that the object is stored to the store because of partials.

Solution: .delete() removes the object and web socket check it before doing it again.

Status

  • Code changes have been tested against the Discord API, or there are no code changes
  • I know how to update typings and have done so, or typings don't need updating

Semantic versioning classification:

  • This PR changes the library's interface (methods or parameters added)
    • This PR includes breaking changes (methods removed or renamed, parameters moved or removed)
  • This PR only includes non-code changes, like changes to documentation, README, etc.

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

2 participants