name: mini-vue description: Guides the agent when working with the local mini-vue framework in this project. Use when the user mentions mini-vue, @mini-vue imports, JSX components in this repo, or asks about how to mount/render components using the custom mini-vue runtime.
Mini Vue (local framework) Skill
This project contains a small Vue-like runtime in the mini-vue directory, exposed via the @mini-vue alias. Use this skill whenever you are working inside this repo with components that import from @mini-vue.
When to Apply This Skill
Use these instructions when:
- The user mentions mini-vue or
@mini-vue - The code imports from
@mini-vue(for example insrc/App.tsx,src/main.tsx, or components) - The user asks how rendering, reactivity, or components work in this project
- The user wants to add or modify components, state, or mounting logic using this custom framework
Project-Specific Conventions
@mini-vueis not the official Vue package; it is a local framework implemented in themini-vuedirectory.- TypeScript and Vite are configured so that:
@mini-vueresolves tomini-vue/index.tsjsxImportSourceis set to@mini-vue- JSX in
.tsxfiles uses the custom runtime defined inmini-vue/jsx-runtime.ts
- Example usage lives in
src/:src/main.tsxmounts the root component usingmountfrom@mini-vue.src/App.tsxand components undersrc/components/demonstrate typical patterns.
Core mini-vue APIs
The public entrypoint mini-vue/index.ts re-exports the main primitives:
component: defines a component using a setup functionmount: mounts a VNode or root renderer into a DOM containerh/ JSX runtime: creates virtual nodes used by the rendererreactive: wraps arrays/objects to make them reactiveref: wraps primitive values with a.valuepropertywatchEffect: runs a reactive effect and re-runs it when dependencies change
component usage
- Components are created by calling
component(setup). - The
setupfunction:- Receives props (typed via generics if needed).
- Can return either:
- A VNode directly, or
- A render function that returns a VNode.
- In this project, components typically return a render function that uses JSX:
import { component } from '@mini-vue'
const MyComponent = component((props: { message: string }) => {
return () => (
<div>{props.message}</div>
)
})
export default MyComponent
Key details:
- Components may be called with
(props, key?). - The internal implementation uses a render scope with slots and keyed slots to reuse component instances across renders.
mount usage
- The
mountfunction accepts either:- A VNode, or
- A root renderer function that returns a VNode.
- In this project, the typical pattern is to pass a root component (created with
component) as the first argument, and a DOM element as the second:
import { mount } from '@mini-vue'
import App from './App'
mount(App, document.getElementById('app'))
Behavior:
- If the source is a function,
mini-vue:- Creates a root render scope via
createRootRenderScope. - Uses
watchEffectto track reactivity. - Calls
renderWithRootScopeto produce the next VNode tree. - On the first run, it mounts the tree; on subsequent runs it calls
patch(prevVNode, nextVNode)to update the DOM.
- Creates a root render scope via
- If the source is a VNode, it is mounted directly via
mountVNode.
Reactivity Patterns
The project demonstrates reactivity in src/components/TodoList.tsx:
reactiveis used for collections (arrays/objects) that should trigger re-renders when mutated:
import { reactive } from '@mini-vue'
const todoItems = reactive([
{ id: Date.now(), todo: 'Do something!', isDone: false },
])
// Mutations like push() are reactive:
todoItems.push({ id: Date.now(), todo: 'Another', isDone: false })
refis used for primitive values:
import { ref } from '@mini-vue'
const newTodo = ref('')
newTodo.value = 'Buy milk'
- Event handlers update refs and reactive state. The JSX event handlers (
onInput,onClick, etc.) ultimately go through thepropssystem inmini-vue/props.tsand are applied to DOM elements inmini-vue/mount.ts.
When modifying or adding components:
- Prefer
reffor single scalar values (string, number, boolean). - Prefer
reactivefor lists/objects that you'll mutate (push, splice, etc.). - Use
watchEffectwhen you need side effects reacting to changes in reactive/refs.
JSX and VNode Basics
- JSX is compiled using
@mini-vue’s JSX runtime (mini-vue/jsx-runtime.ts). - The
hfunction (and JSX) produce VNode objects with shape similar to:tag: string tag nameprops: prop bagchildren: array of strings or VNodes
mini-vue/mount.tshandles:- Creating actual DOM elements (
document.createElement) - Applying props via
applyPropfrommini-vue/props.ts - Recursively mounting children.
- Creating actual DOM elements (
When writing JSX:
- Use HTML tag names (
div,button,input, etc.) for DOM elements. - Use PascalCase for components created with
component. - Pass props and event handlers like in React/Vue JSX:
<input
class="border border-black px-1 py-0.5 block mb-4"
value={newTodo.value}
onInput={handleInput}
/>
Example: Adding a New Component
To add a new component in this project:
- Create a
.tsxfile undersrc/components/, e.g.NewItem.tsx. - Import
componentand any reactivity primitives needed from@mini-vue. - Define the component using a setup function that returns a render function.
- Use JSX to describe the UI.
- Import and render it from
App.tsxor another component.
Example:
// src/components/NewItem.tsx
import { component } from '@mini-vue'
export default component((props: { label: string }) => {
return () => (
<span>{props.label}</span>
)
})
// src/App.tsx
import { component } from '@mini-vue'
import NewItem from './components/NewItem'
export default component(() => {
return () => (
<div>
<NewItem label="Hello mini-vue" />
</div>
)
})
Agent Guidance
When assisting in this project:
- Do not treat
@mini-vueas an external npm dependency; it is local code undermini-vue/. - Prefer using the existing primitives (
component,mount,reactive,ref,watchEffect) rather than re-implementing core framework behavior. - When explaining behavior, reference the implementation files (
mini-vue/component.ts,mini-vue/mount.ts,mini-vue/reactive.ts, etc.) instead of generic Vue/React internals. - Ensure new code:
- Stays consistent with current patterns in
src/App.tsxandsrc/components/*. - Respects the TypeScript configuration (
jsxImportSource,paths, and strict mode).
- Stays consistent with current patterns in
Additional Resources
If you need more detail:
- Inspect the implementation files under
mini-vue/for low-level behavior. - Look at
src/components/TodoList.tsxandsrc/components/TodoItem.tsxfor idiomatic usage examples in this repo.