Skip to content

refactor(frontend): Extract generic storeAction() wrapper#119

Merged
enko merged 3 commits intomainfrom
refactor/store-action-wrapper
Mar 4, 2026
Merged

refactor(frontend): Extract generic storeAction() wrapper#119
enko merged 3 commits intomainfrom
refactor/store-action-wrapper

Conversation

@enko
Copy link
Copy Markdown
Member

@enko enko commented Mar 4, 2026

Summary

  • Introduces a reusable storeAction() helper that handles the repetitive isLoading/error/try-catch pattern used across all store operations
  • Applied to friends.ts, circles.ts, encounters.ts, and collectives.ts
  • Reduces total store code from 2,848 to 1,535 lines (~46% reduction, ~1,313 lines eliminated)

Test plan

  • Verify all friend CRUD operations work (create, read, update, delete)
  • Verify subresource operations (phones, emails, addresses, URLs, dates, social profiles, professional history, relationships, circles)
  • Verify circle CRUD and reorder/merge operations
  • Verify encounter CRUD operations
  • Verify collective CRUD and member management
  • Confirm loading spinners and error messages still display correctly

Closes #112

🤖 Generated with Claude Code

…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>(
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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 used

No urgency given the codebase currently has no frontend tests, but worth doing before this utility grows further.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 4, 2026

🔍 Automated Code Review

Commit a29631d
Reviewed 2026-03-04T20:30:00Z
Status ✅ Approved

Findings

Severity Count
🚨 Critical 0
⚠️ Important 0
💡 Suggestion 1

AGENTS.md Compliance

  • ✅ Security requirements
  • ✅ Architecture patterns (Svelte stores, API client usage)
  • ✅ Testing standards (suggestion filed inline)

Summary

This is a well-executed refactor that eliminates ~1,313 lines of repetitive boilerplate by extracting a generic storeAction() wrapper. The abstraction is sound: it preserves all prior behaviour (loading/error state transitions, error re-throwing, optional onError cleanup), correctly applies success state after the spread so isLoading/error always win, and keeps the two non-conforming methods (loadRelationshipTypes, searchFriends) manual with their own ApiError handling. The filter state extraction into friendListFilter.ts and subresource extraction into friendSubresources.ts improve modularity without breaking imports (re-exported from friends.ts). The one open suggestion is to add unit tests for storeAction itself — see inline comment.


🤖 Automated review by Claude Code • View CI Run

enko and others added 2 commits March 4, 2026 21:40
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>
Copy link
Copy Markdown

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found on commit a29631d. Refactor is clean and correct — see existing inline suggestion for unit tests on storeAction.

@enko enko merged commit 589a1a1 into main Mar 4, 2026
5 checks passed
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 4, 2026

🎉 This PR is included in version 2.65.4 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(frontend): Extract generic store action wrapper to eliminate ~1,500 lines of boilerplate

1 participant