Commit Graph

5 Commits

Author SHA1 Message Date
Florian Schroedl
4510b6f736 fix: narrow CLJS watch path to avoid infinite recompile loop
Watch path `example/todomvc` included the `js/` output directory,
causing each compile to trigger another. Narrowed to
`example/todomvc/pocketbook` (source only).
2026-04-16 19:51:48 +02:00
Florian Schroedl
86b54e1291 refactor: extract shared .cljc library with store protocol
Move core, sync, and transit from platform-specific .clj/.cljs to
shared .cljc files with reader conditionals. This enables testing
the full sync logic on the JVM and using SyncedAtom from Clojure
clients.

Key changes:
- PStore protocol (store.cljc) decouples core from storage backend
- IDB store (store/idb.cljs) and memory store (store/memory.cljc)
- SyncedAtom implements CLJ IDeref/IAtom/IRef + CLJS equivalents
- Sync client uses java.net.http on CLJ, fetch on CLJS
- SSE remains CLJS-only; JVM clients use polling
- API change: store passed explicitly instead of pb/open
- 7 new JVM tests: local ops, persistence, watches, two-client sync
- 28 tests total, 87 assertions, all passing
2026-04-16 19:42:06 +02:00
Florian Schroedl
38a15b7a34 fix: CLJS watch mode missing todomvc from cljs_deps.js
Two issues caused "Loading from local store..." after tmux restart:

1. Watch path only included `src/`, so `example/todomvc/` sources
   weren't compiled on the watcher's initial build, leaving
   pocketbook.todomvc out of cljs_deps.js.
   Fix: `-w "src:example/todomvc"`

2. Stale output dir from previous builds caused incremental compile
   to skip regenerating cljs_deps.js.
   Fix: `cljs:clean` task (deletes js output) runs before `cljs:watch`.
2026-04-04 18:38:22 +02:00
Florian Schroedl
570a087f53 refactor: move TodoMVC example into example/ directory
- example/todomvc/pocketbook/todomvc.cljs — app source
- example/todomvc/todomvc.html — page
- example/todomvc/js/ — compiled output (gitignored)

Server static file serving is now filesystem-based via --static-dir
flag instead of classpath resources. No static dir by default (API
only); bb server passes --static-dir example/todomvc.

Removed resources/public/ — library has no bundled static assets.
2026-04-04 17:05:12 +02:00
Florian Schroedl
55cddf751b feat: implement Pocketbook — a Clojure-native synced atom
Offline-first key-value store with atom interface (swap!, deref,
add-watch) that syncs to a SQLite-backed server over Transit.

Server (CLJ):
- SQLite storage with Nippy serialization preserving all Clojure types
- GET /sync?group=G&since=T pull endpoint with prefix-based groups
- POST /sync push endpoint with per-document version checking
- Conflict detection (stale write rejection)
- Token-based auth with per-user group access
- CORS support, soft deletes, purge compaction

Client (CLJS):
- IndexedDB wrapper with Transit serialization
- SyncedAtom implementing IAtom (IDeref, ISwap, IReset, IWatchable)
- Write-through to IndexedDB on every swap!
- Background sync loop (pull + push) with configurable interval
- Online/offline detection with reconnect sync
- Conflict resolution (accept server value)
- ready? channel for initial load
- Custom cache atom support (Reagent ratom compatible)

25 tests, 77 assertions across db, transit, server, and auth.
2026-04-04 16:33:14 +02:00