Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ node_modules
/types
/docs
/coverage
.claude
66 changes: 66 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Project Overview

Madrone is an object composition and reactivity framework for JavaScript/TypeScript. It provides reactive state management with support for computed properties, watchers, and integration with Vue 3's reactivity system.

Documentation: https://madronejs.github.io/docs/core/

## Common Commands

```bash
pnpm test # Run tests in watch mode (vitest)
pnpm test-ci # Run tests once with coverage
pnpm lint # Run ESLint on src/
pnpm build # Build library with Vite
pnpm build-types # Generate TypeScript declarations
pnpm build-all # Clean, build, and generate types
```

Run a single test file:
```bash
pnpm test src/reactivity/__spec__/watcher.spec.ts
```

## Architecture

### Core Layers

1. **Reactivity System** (`src/reactivity/`)
- `Reactive.ts` - Creates reactive proxies for objects/arrays using `Proxy`. Handles deep reactivity by default.
- `Observer.ts` - The `ObservableItem` class that tracks dependencies and caches computed values. Manages dirty state and change notifications.
- `Computed.ts` - Factory for creating cached computed properties via Observer
- `Watcher.ts` - Watches reactive expressions and calls handlers on change
- `global.ts` - Core dependency tracking infrastructure: proxy/target mappings, observer-to-dependency graphs, and microtask scheduler

2. **Integration Layer** (`src/integrations/`)
- `MadroneState` - Default integration using Madrone's own reactivity (loaded by default)
- `MadroneVue3` - Integration that bridges Madrone objects with Vue 3's reactivity system

3. **Public API** (`src/auto.ts`, `src/decorate.ts`, `src/index.ts`)
- `auto()` - Makes all properties on an object reactive/computed automatically
- `define()` - Defines a single reactive or computed property
- `watch()` - Watches reactive expressions
- `@reactive` / `@computed` - Decorators for class-based usage

### Key Patterns

**Integration System**: Madrone uses a plugin architecture (`Integration` interface in `interfaces.ts`). Integrations define how reactive/computed properties are created. The last added integration becomes active.

```typescript
Madrone.use(MadroneVue3({ reactive, toRaw })); // Switch to Vue 3 reactivity
Madrone.unuse(integration); // Remove integration
```

**Dependency Tracking**: When a computed runs its getter, `getCurrentObserver()` returns the active Observer. Reactive proxies call `dependTracker()` on property access to register dependencies. When reactive values change, `trackerChanged()` marks dependent observers dirty.

**Path Alias**: The codebase uses `@/` as an alias for `./src/` (configured in tsconfig.json and vite.config.ts).

## Test Structure

Tests use Vitest and are colocated in `__spec__` directories:
- `src/__spec__/` - Tests for decorators, merge utility, examples
- `src/reactivity/__spec__/` - Tests for reactive, observer, watcher
- `src/integrations/__spec__/` - Tests for MadroneState and Vue3 integration
15 changes: 14 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,24 @@
"types": "./types/index.d.ts",
"import": "./dist/core.js",
"require": "./dist/core.umd.cjs"
},
"./vue": {
"types": "./types/integrations/vue.d.ts",
"import": "./dist/vue.js",
"require": "./dist/vue.umd.cjs"
}
},
"peerDependencies": {
"vue": "^3.0.0"
},
"peerDependenciesMeta": {
"vue": {
"optional": true
}
},
"files": [
"dist/*.js",
"dist/*.mjs",
"dist/*.cjs",
"types/**/*.d.ts"
],
"repository": {
Expand Down
38 changes: 7 additions & 31 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading