refactor(frontend): Extract generic storeAction() wrapper#119
Conversation
…e store boilerplate Introduces a reusable storeAction() helper that handles the repetitive isLoading/error/try-catch pattern used across all store operations. Applied to friends, circles, encounters, and collectives stores, reducing total store code from 2,848 to 1,535 lines (~46% reduction). Closes #112 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
| * Reduces typical store operations from ~25 lines to ~3-5 lines by | ||
| * automatically managing isLoading and error state transitions. | ||
| */ | ||
| export async function storeAction<S extends { isLoading: boolean; error: string | null }, T>( |
There was a problem hiding this comment.
💡 Suggestion: Add unit tests for this utility
storeAction is now the backbone of all store operations across 4 files. A small test suite here would give regression protection for the entire store layer cheaply.
Useful cases to cover:
// Happy path — calls apiFn, merges onSuccess partial, resets isLoading/error
// Error path — sets error message, calls onError partial if provided, still throws
// onError omitted — partial defaults to {} (no extra state mutation)
// ApiError vs unknown error — message vs fallbackError string usedNo urgency given the codebase currently has no frontend tests, but worth doing before this utility grows further.
🔍 Automated Code Review
Findings
AGENTS.md Compliance
SummaryThis is a well-executed refactor that eliminates ~1,313 lines of repetitive boilerplate by extracting a generic 🤖 Automated review by Claude Code • View CI Run |
Splits the 806-line friends.ts into three focused files: - friends.ts (194 lines) — core friend CRUD, derived stores, re-exports - friendSubresources.ts (542 lines) — all subresource CRUD operations - friendListFilter.ts (94 lines) — filter/search state persistence All existing imports from '$lib/stores/friends' continue to work unchanged via re-exports. No consumer changes needed. Closes #113 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Export FriendListFilterState interface for consumer type annotations - Extract buildSearchParams/parseSearchParams as standalone pure utility functions instead of store methods (cleaner API, no need to pass state back to the store) - Re-export new symbols from friends.ts barrel Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
✅ No new issues found on commit a29631d. Refactor is clean and correct — see existing inline suggestion for unit tests on storeAction.
|
🎉 This PR is included in version 2.65.4 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Summary
storeAction()helper that handles the repetitiveisLoading/error/try-catchpattern used across all store operationsfriends.ts,circles.ts,encounters.ts, andcollectives.tsTest plan
Closes #112
🤖 Generated with Claude Code