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

refactor: event modernization and optimization #2404

Merged
merged 14 commits into from Apr 21, 2024
Merged

Conversation

jhildenbiddle
Copy link
Member

@jhildenbiddle jhildenbiddle commented Apr 11, 2024

Summary

The motivation for this PR is to remove/replace event handling code no longer needed for legacy browsers and to optimize event handling so that we can more easily address the many scroll-related issues for the upcoming v5 release or in a future release following v5.

No features or tests have been added or removed. All of the pre-existing tests continue to pass.

Updates to Docsify's event handling are as follows:

  • Replace code no longer required for legacy browser compatibility with modern, native web APIs
  • Remove dependencies no longer required for legacy browser compatibility
  • Optimize performance by utilizing modern, native web APIs to reduce/remove reflows, repaints, manual calculations, and successive/unnecessary function calls (e.g., IntersectionObserver instead of scroll events)
  • Simplify event-related codebase by improving function names, using a consistent naming convention, adding JSDoc-style comments, and isolating function tasks and side effects.

Included but not directly event-handling related:

  • Removed unused SSR code
  • Minor cleanup of NPM scripts

NOTES:

  • Almost all of the event-related changes are found in /src/core/event/index.js. Other file updates are either small changes to accommodate the updates to /src/core/event/index.js or are unrelated build-related changes.
  • If I could have isolated the event-handling changes into separate smaller PRs, I would have. The pre-existing event handling was intertwined between multiple files and poorly named methods, making it far easier to fix in a single PR.

Related issue, if any:

None

What kind of change does this PR introduce?

Bugfix
Code style update
Refactor

For any code change,

N/A

Does this PR introduce a breaking change?

No

Tested in the following browsers:

  • Chrome
  • Firefox
  • Safari

- Refactor methods names and functionality
- Replace scroll listeners with observers
- Replace Tweezer-based scrolling with native scroll methods
- Remove tweezer.js dependency
- Remove redundant method calls
- Rename $resetEvents to onNavigate
- Rename __scrollActiveSidebar to onRender
- Remove __getAndActive
- Remove __sticky
Copy link

vercel bot commented Apr 11, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docsify-preview ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 17, 2024 8:20pm

@jhildenbiddle jhildenbiddle added this to the 5.x milestone Apr 11, 2024
@jhildenbiddle jhildenbiddle self-assigned this Apr 11, 2024
@jhildenbiddle jhildenbiddle marked this pull request as draft April 11, 2024 16:02
@jhildenbiddle jhildenbiddle marked this pull request as ready for review April 16, 2024 15:14
@jhildenbiddle jhildenbiddle requested a review from a team April 16, 2024 15:14
# Conflicts:
#	src/core/event/index.js
@jhildenbiddle jhildenbiddle changed the title feature: event refactor and modernization refactor: event modernization and optimization Apr 19, 2024
Copy link
Member

@Koooooo-7 Koooooo-7 left a comment

Choose a reason for hiding this comment

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

LGTM.

@Koooooo-7 Koooooo-7 requested a review from a team April 19, 2024 10:28
@sy-records sy-records requested a review from a team April 21, 2024 08:03
@jhildenbiddle jhildenbiddle merged commit bb902f8 into develop Apr 21, 2024
9 checks passed
@jhildenbiddle jhildenbiddle deleted the events-overhaul branch April 21, 2024 12:44
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

3 participants