Commit fe0ce79
refactor: introduce generic lock method for TCA-independent architecture (#225)
* refactor: move core lock methods from Effect+LockmanInternal to LockmanManager
This refactoring enables TCA-independent usage of core Lockman functionality
by moving handleError and acquireLock methods to LockmanManager as static methods.
## Changes Made
### Core Architecture Changes
- **LockmanManager.handleError()**: New static method for TCA-independent error handling
- **LockmanManager.acquireLock()**: New static method for TCA-independent lock acquisition
- **Effect+LockmanInternal**: Updated all internal calls to use LockmanManager directly
- **Removed delegation patterns**: Eliminated intermediate Effect static methods
### API Improvements
- **Universal Swift Compatibility**: Core lock management now works in SwiftUI, UIKit, Vapor, etc.
- **Cleaner Direct Access**: `LockmanManager.handleError()` and `LockmanManager.acquireLock()`
- **Maintained TCA Integration**: All existing Effect-based lock management continues to work
### Test Coverage
- **LockmanManagerTests**: Added comprehensive unit tests for new static methods
- **Updated Effect Tests**: Modified to use new direct API calls
- **100% Backward Compatibility**: All existing tests pass without modification
## Impact
- **Breaking Change**: None - all existing APIs maintained
- **New Capability**: TCA-independent lock management for universal Swift usage
- **Architecture**: Transforms Lockman from TCA-only to universal Swift library
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <[email protected]>
* refactor: remove unused effectBuilder lock method and tests
Clean up codebase by removing the unused internal static lock method
with effectBuilder parameter and its associated test methods.
## Removed Items
- `Effect.lock(effectBuilder:...)` internal static method
- `testInternalStaticLockWithEffectBuilder()` test method
- `testInternalStaticLockWithEffectBuilderError()` test method
- `testInternalStaticLockWithNilUnlockOption()` test method
- `testInternalStaticLockEffectBuilderWithCancelResult()` test method
## Impact
- **Code Simplification**: Eliminated 60+ lines of unused code
- **Maintained Functionality**: All functionality preserved through `reducer:` parameter method
- **Test Coverage**: Removed 4 test methods that tested unused code paths
- **No Breaking Changes**: Only internal methods removed, no public API impact
This cleanup improves code maintainability by removing dead code paths
and focuses testing on actually used functionality.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <[email protected]>
* refactor: rename 'reducer' parameter to 'effectBuilder' for clarity
Improved parameter naming in internal Effect.lock method for better
code readability and semantic correctness.
## Changes Made
- **Parameter Rename**: `reducer:` → `effectBuilder:` in internal static method
- **Usage Updates**: Updated all call sites to use `effectBuilder:` parameter
- **Documentation**: Updated method documentation and usage examples
- **Test Updates**: Updated all test cases to use new parameter name
## Rationale
The parameter name 'reducer' was misleading since the closure:
1. `{ concatenatedEffect }` - Returns pre-built Effect (not reducer)
2. `{ operation }` - Returns pre-built Effect (not reducer)
3. `{ .run { ... } }` - Creates new Effect (effect builder pattern)
4. `{ self.base.reduce(...) }` - Only this case involves actual reducer
The name 'effectBuilder' accurately describes the closure's purpose:
**building or returning Effects**, regardless of the creation method.
## Impact
- **No Breaking Changes**: Internal API only, no public interface changes
- **Improved Code Clarity**: Parameter name now matches actual usage patterns
- **Better Developer Experience**: More intuitive parameter naming
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <[email protected]>
* refactor!: redesign LockmanResult as generic type with unlockToken associated values
BREAKING CHANGES:
- LockmanResult is now generic LockmanResult<B, I> with unlockToken as associated values
- LockmanManager.acquireLock now returns LockmanResult<B, I> instead of tuple
- Strategy-level operations now return LockmanStrategyResult (moved to separate file)
- All success cases now include unlockToken as associated value, eliminating nil handling
Key improvements:
- Type-safe unlockToken access through pattern matching
- Eliminates tuple destructuring API in favor of enum cases
- Compiler-guaranteed unlockToken availability for successful locks
- Cleaner separation between manager-level and strategy-level results
Migration:
- Replace tuple destructuring: let (result, token) = acquireLock(...)
- Use pattern matching: if case .success(let token) = acquireLock(...)
- Strategy implementations should return LockmanStrategyResult instead of LockmanResult
- Update test code to use new pattern matching API
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <[email protected]>
* refactor: implement generic lock method with TCA-independent architecture
- Add universal LockmanManager.lock() method with callback-based interface
- Support both TCA and non-TCA environments through flexible return types
- Consolidate Effect+LockmanInternal.swift into Effect+Lockman.swift
- Refactor Effect.lock() methods to use generic implementation
- Update LockmanReducer to use new generic lock method
- Add comprehensive test suite for generic lock functionality
- Maintain full backward compatibility and type safety
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <[email protected]>
* refactor: remove unused LockmanInternalError type
- Remove LockmanInternalError enum and missingUnlockToken case
- Generic lock implementation provides type-safe unlock tokens
- No longer needed due to improved architecture design
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <[email protected]>
---------
Co-authored-by: Claude <[email protected]>1 parent 21c0c34 commit fe0ce79
File tree
6 files changed
+573
-855
lines changed- Sources/Lockman
- Composable
- Core
- Tests/LockmanTests/Unit
- Composable
- Core
6 files changed
+573
-855
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
78 | | - | |
79 | | - | |
80 | | - | |
| 78 | + | |
| 79 | + | |
81 | 80 | | |
82 | 81 | | |
83 | 82 | | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
89 | 124 | | |
90 | 125 | | |
91 | 126 | | |
| |||
158 | 193 | | |
159 | 194 | | |
160 | 195 | | |
161 | | - | |
162 | | - | |
163 | | - | |
| 196 | + | |
| 197 | + | |
164 | 198 | | |
165 | 199 | | |
166 | 200 | | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
172 | 242 | | |
173 | 243 | | |
174 | 244 | | |
This file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
90 | 89 | | |
91 | 90 | | |
92 | 91 | | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
98 | 135 | | |
99 | 136 | | |
100 | 137 | | |
| |||
0 commit comments