Learn from VueUse.
Try to implement VueUse functions by yourself and then think:
- Why is my impl different from VueUse's? What are my mistakes?
- Can I just ignore some differences to focus on core logic? What are they work for?
- Is my impl better than VueUse's in some aspects?
Use .md
files to record these valuable thoughts.
Here are recommendations about how to start:
- First of all, clone VueUse source code.
- Choose a VueUse function that you are interested in.
- Create the same directory structure for this function as VueUse done.
- Copy the following items as the specification:
Type Declarations
in the online docdemo.vue
- Tests (end with
.test.ts
)
- Try to implement this function.
- You can import
demo.vue
inexample
web project and executenpm run dev
to see whether it works (VueUse inspectsdemo.vue
in VitePress static site, which needs more configurations). - Run tests to make sure your impl works right.
- Compare your impl with VueUse's, correct mistakes and write docs (you can save your original impl in
index.my.ts
).
To focus on the logic, we can ignore some requirements:
- Compatible with Vue2 (lib
vue-demi
works for this purpose) - Support directive and component use
- Rely on other shared functions (you can make it up later)