PrismJS / PrismJS/prism

[v2] Simplify hooks

Open
#3,904 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
13k
Forks
1.4k
Avg merge
15h 36m
Merged PRs (30d)
3

Description

It appears a lot of complexity has been introduced into hooks to support TypeScript. This is the wrong order of dependencies: TypeScript exists to support our code, our code should not have to jump through hoops to support TypeScript.

I suggest refactoring this back to something closer to how hooks used to be, or (probably better) just adopting https://www.npmjs.com/package/blissful-hooks and making any typing changes there (as a separate .d.ts file).

This includes:

  • src/hook-state.ts: Unclear why this needs to exist at all
  • src/hooks.ts: Hardcoding all hooks is contrary to the very idea of hooks. Plugins can add hooks too!
  • Remove src/shared/hooks-util.ts: Any functionality we need from there should be part of the hooks class. It seems to be used exclusively by plugins. Plugins should be accessing hooks from the Prism object, via Prism.hooks.

@RunDevelopment if I'm missing some context here, please let me know!

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading src/hook-state.ts, src/hooks.ts, and src/shared/hooks-util.ts, then trace how plugins access hooks through Prism. Compare the current design with the stated goal of allowing plugin-added hooks and keeping TypeScript declarations separate. Done means the unnecessary hook state and shared utility are removed, hooks are no longer hardcoded, and plugin access follows Prism.hooks.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
developer-experience, tooling
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.