-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
convert Docsify to an ES class to start modernizing the code base #1206
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/docsify-core/docsify-preview/chyzxa7de |
There are no logic changes in this PR. Turn on "hide whitespace changes" to get a more clear picture of the change. |
renderMixin(proto); | ||
fetchMixin(proto); | ||
eventMixin(proto); | ||
const { Docsify } = require('../src/core/Docsify'); |
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.
we can just import the class and use it instead of re-creating it. Also makes the test more resilient in case someone updates the class but forget to update the test and the old test would still pass.
…ication site (update buble to fix an unhelpful error message)
…orts the Docsify class
* develop: Update build/css.js use a port for the tests that doesn't collide with common local server ports Revert "Updated docs site dark and light mode with switch and redesigned search bar using docsify-darklight-theme" (#1207) ci: added codesandbox build preview for PR reviews (#1193) Update cover.md (#1134) chore: update auto format config
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 918574a:
|
e2e tests failed again (flaky). Re-running them. |
@@ -1,5 +1,8 @@ | |||
import { documentReady } from './util/dom'; | |||
import { Docsify } from './Docsify'; | |||
import initGlobalAPI from './global-api'; | |||
|
|||
initGlobalAPI(); |
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.
This is a small change: I moved initGlobalAPI
call from Docsify.js
to index.js
so that importing Docsify.js
has no side-effects.
@@ -0,0 +1,50 @@ | |||
import { noop } from '../util/core'; |
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.
I move lifecycle
to its own mixin instead of being niside the init
mixin folder. Better organization I think.
@@ -0,0 +1,12 @@ | |||
import { isFn } from '../util/core'; |
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.
This used to be located in the same file as init
mixin, so I moved it to it's own file. Better organization I think.
/** | ||
* This class compiles the markdown of each page of a Docsify site into HTML | ||
* (using some information from the provided router). | ||
*/ |
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.
Good idea to add inline documentation me thinks. It shows up in the intellisense of your editor when hovering on the function. Make things easier to learn.
|
||
// Bind event | ||
this._bindEventOnRendered(activeEl); | ||
} |
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.
I made literally no logic changes. I only moved the code around within the file, so that all functions are now methods inside the new classes.
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.
Finally got around to taking a look at this (apologies for the delay).
My feeling is that while I'm all for cleaning up the codebase, refactors like this should not be part of a project branch or version that maintainers are trying to stabilize and put into maintenance mode. This is under-the-hood stuff, so forcing these changes into 4.x adds no value for users and introduces unnecessary risk for maintainers.
Ideally, I'd prefer we triage the existing issues, get all hands to focus on knocking out the 4.x issues, then turn towards 5.x work (which would include this refactor). Getting through the 4.x work is going to be really hard to do if some folks are trying to resolve issues while a refactor is taking place at the same time.
Hope this doesn't sound discouraging. It definitely isn't meant to be. I think there are some solid changes in here and I'd love to see them merged, just not for v4.
If majority agrees to wait until the next major release to merge this, I can keep merging develop into this branch to keep this updated and ensure tests are passing. Let's focus on adding tests for each new pull request. |
We dont have to wait for next major release to merge this. This seems like a non-breaking change and it doesn't effect the behavior of the core. I guess you dont have to update the branch as it will increase the comments here. We can update it before merge as it gets approvals. Yea, tests would be awesome. |
* develop: docs: removed codefund docs and plugin (#1262) docs: remove bundle size from the home page and documentation (#1257) fix: search can not search the table header (#1256) fix: after setting the background image, the button is obscured (#1234) Fix: fixed onlycover flag in mobile (#1243) fix: Updated docs with instructions for installing specific version (fixes #780) (#1225) fix: Add error handling for missing dependencies (fixes #1210) (#1232) [documdocs: deploy docsify in docker. (#1241) docs: Add embed gist instructions to Embed Files (fixes #932 ) (#1238) chore: add changelog 4.11.4 [build] 4.11.4 feat: added html sanitizer for remote rendering (#1128)
this._renderTo('.cover-main', html); | ||
sticky(); | ||
}; | ||
_render_updateRender() { |
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.
There was previously two functions, both named updateRender
, one in the router mixin, one in the render mixin, which is confusing. They were both plain functions
before (so basically "private" methods), but now that they are both on this
, I renamed them to _render_updateRender
and _router_updateRender
so they can be differentiated. We can clean it or find better names later...
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.
Apart from this change, nothing major other than converting to classes and all functions are methods.
The changes in this PR aren't too complicated, mostly just syntax changes, and renamed some functions. It starts to give us better intellisense support in IDEs like VS Code because of the I am willing to help resolve any conflicts in other PRs that this may cause. |
Closing this in favor of #1685 |
This is a Draft PR (WIP). It is forked from #1189. Once that is merged, then I will change the base of this PR to
develop
and mark the PR as ready-for-review instead of a draft.Summary
Start to modernize the code base. In this case I converted
Docsify
toclass
syntax. This paves the way for better intellisense in VS Code (which is already powered by TypeScript). We are then closer to moving to TypeScript if we wish to in the future.Now if we mark any of the methods and properties with JSDoc comments, VS Code will know how to map them whenever hovering on any methods/properties of the Docsify instance (thanks to class syntax). We just need to add JSDoc comments, but that can be in a later PR.
What kind of change does this PR introduce? (check at least one)
If changing the UI of default theme, please provide the before/after screenshot:
Does this PR introduce a breaking change? (check one)
If yes, please describe the impact and migration path for existing applications:
The PR fulfills these requirements:
fix #xxx[,#xxx]
, where "xxx" is the issue number)You have tested in the following browsers: (Providing a detailed version will be better.)
If adding a new feature, the PR's description includes: