Skip to content

Commit 7555574

Browse files
Merge pull request #5 from zeixcom/cause-effect-v0-18
Update to Cause & Effect v0.18
2 parents 57d8adf + 4d7faed commit 7555574

File tree

302 files changed

+7372
-6520
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

302 files changed

+7372
-6520
lines changed

.ai-context.md

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ The selector function provides type-safe DOM queries:
3636
({ first, all }) => ({
3737
button?: first('button'), // HTMLButtonElement | undefined
3838
input: first('input', 'required'), // HTMLInputElement (throws if missing)
39-
items: all('.item'), // Collection<HTMLElement>
39+
items: all('.item'), // Memo<HTMLElement[]>
4040
custom?: first<MyElement>('my-el') // Custom typing
4141
})
4242
```
4343

44-
Collections are reactive arrays that emit `add`/`remove` events and track DOM mutations automatically.
44+
`all()` returns `Memo<E[]>` backed by a lazy `MutationObserver` that tracks DOM mutations automatically.
4545

4646
### Effect System
4747
Effects run reactively when dependencies change:
@@ -77,9 +77,10 @@ Effects run reactively when dependencies change:
7777
- `setStyle(property, reactive)` - Update inline styles
7878

7979
### Advanced
80-
- `pass(props)` - Pass properties to child components
81-
- `dangerouslySetInnerHTML(reactive)` - Set innerHTML (use carefully)
82-
- `insertOrRemoveElement(reactive, inserter)` - Dynamic element creation/removal
80+
- `pass(props)` - Pass reactive values to child Le Truc components via Slot signal replacement
81+
- `dangerouslySetInnerHTML(reactive, opts?)` - Set innerHTML (use only for trusted sources)
82+
- `callMethod(name, reactive, args?)` - Call a method when reactive is truthy
83+
- `focus(reactive)` - Focus element when truthy
8384

8485
## Parsers
8586

@@ -114,23 +115,23 @@ const countSignal = createState(0)
114115
setText(() => countSignal.get())
115116
```
116117

117-
## Collections
118+
## Element Memos
118119

119-
Read-only reactive element arrays with array-like interface:
120+
`all()` returns `Memo<E[]>` — a lazily observed collection of elements:
120121

121122
```typescript
122123
// Creation
123-
({ all }) => ({ items: all('.item') }) // In UI query, will be ui.items
124-
const items = createCollection(parent, '.item') // Elsewhere with arbitrary parent
124+
({ all }) => ({ items: all('.item') }) // In UI query, will be ui.items
125+
const items = createElementsMemo(parent, '.item') // Elsewhere with arbitrary parent
125126

126127
// Access
127-
items.get() // Get current elements
128-
items.length // Reactive length
129-
items[0] // Index access
130-
items.on('add', fn) // Listen for additions
131-
items.on('remove', fn) // Listen for removals
128+
items.get() // Get current elements array
129+
items.get().length // Current count
130+
items.get()[0] // Index access
132131
```
133132

133+
The `MutationObserver` backing the memo activates lazily — only when the memo is read from within a reactive effect. This avoids unnecessary observation overhead for memos that aren't actively consumed.
134+
134135
## Common Patterns
135136

136137
### Form Components
@@ -222,7 +223,7 @@ export default defineComponent<MyComponentProps, MyComponentUI>(...)
222223

223224
### Performance
224225
- Effects automatically optimize re-runs when dependencies don't change
225-
- Collections efficiently track only actual DOM changes
226+
- Element memos efficiently track only actual DOM changes via lazy MutationObserver
226227
- Use `schedule()` for non-critical updates in passive event handlers
227228
- Proper cleanup prevents memory leaks
228229

.github/copilot-instructions.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ Files to consult for examples and authoritative patterns
3232
- Selector helpers & mutation-observer logic: `src/ui.ts`
3333
- Parser implementations: `src/parsers/*.ts` (e.g. `json.ts`, `number.ts`, `string.ts`)
3434
- Effect implementations: `src/effects/*.ts` (exported from root `index.ts`)
35-
- Signal helpers: `src/signals/*.ts` (collection, sensor)
35+
- Event-driven sensors: `src/events.ts` (createEventsSensor)
36+
- Element memos: `createElementsMemo` in `src/ui.ts`
3637
- Examples demonstrating usage: `examples/*` (start from `basic-hello` and `basic-counter`)
3738

3839
Developer workflows (essential commands)
@@ -45,7 +46,7 @@ Developer workflows (essential commands)
4546
What to change (and what to avoid)
4647
- Change: small refactors that preserve exported API in `index.ts` and `.d.ts` files.
4748
- Change: add or update examples in `examples/` to demonstrate new or changed behavior.
48-
- Avoid: breaking changes to public exports without updating `index.ts` / `index.dev.ts` and re-building (`bun run build:dev`).
49+
- Avoid: breaking changes to public exports without updating `index.ts` and re-building (`bun run build`).
4950
- Avoid: changing the custom element registration pattern (i.e., calling `customElements.define`) in a way that prevents `getHelpers` dependency detection.
5051

5152
PR guidance / descriptions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,6 @@ dist
144144
# Vite logs files
145145
vite.config.js.timestamp-*
146146
vite.config.ts.timestamp-*
147+
148+
# Claude
149+
.claude

.zed/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"project_name": "Le Truc",
3+
}

0 commit comments

Comments
 (0)