unwrapped 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +25 -16
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
# Unwrapped
|
|
2
2
|
|
|
3
|
-
A TypeScript library for
|
|
3
|
+
A TypeScript library for handling more gracefully synchronous and asynchronous operations that can fail via Result types. Provides also utilities for caching and binding for popular web frameworks.
|
|
4
4
|
|
|
5
5
|
## Overview
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Error handling in TypeScript is fundamentally built around throwing exceptions and catching them with try/catch blocks. This works fine for simple scripts where an unexpected error should crash the program, but modern applications—especially frontends—need to handle errors gracefully without crashing the entire app.
|
|
8
|
+
|
|
9
|
+
**Unwrapped** provides a different approach by providing Result types, with variants for both synchronous and asynchronous operations.
|
|
10
|
+
While their primary and most basic use are for describing the result of operations that may fail, they can be chained to describe chains of operations, with build-in short-circuiting when encoutering an error. These chains can be described either by successively calling methods like `.chain()`, or by using a generator syntax inspired by Effect (although much simplified).
|
|
11
|
+
|
|
12
|
+
Without **Unwrapped**, the traditional approach leads to scattered state management: separate variables for loading, error, and data, manual state transitions, and the ever-present risk of forgetting to set loading = false in a finally block. Error types are unknown, forcing type assertions everywhere. Chaining multiple async operations that can each fail becomes a mess of nested try/catch blocks or promise chains with multiple .catch() handlers.
|
|
13
|
+
|
|
14
|
+
On the contrary, **Unwrapped**'s AsyncResult type wraps loading, error, and success states in one type allowing for a much leaner and less error prone way of writing. Unsettled asynchronous operations will always give you an AsyncResult in a loading state, and when this work finishes, the AsyncResult will always be in a settled state, being either error or success.
|
|
15
|
+
|
|
16
|
+
**Unwrapped** is composed of multiple sub-modules :
|
|
8
17
|
|
|
9
18
|
- **Core**: Framework-agnostic utilities for managing results and async operations
|
|
10
19
|
- **Vue**: Vue 3 composables and components for reactive async state management
|
|
@@ -19,6 +28,20 @@ A brief comparison with other libraries can be found at the "Why Unwrapped ?" se
|
|
|
19
28
|
npm install unwrapped
|
|
20
29
|
```
|
|
21
30
|
|
|
31
|
+
## API Reference
|
|
32
|
+
|
|
33
|
+
### Core Module (`unwrapped/core`)
|
|
34
|
+
|
|
35
|
+
- **`Result<T, E>`**: Synchronous result type
|
|
36
|
+
- **`AsyncResult<T, E>`**: Asynchronous result with state tracking
|
|
37
|
+
- **`ErrorBase`**: Base error class with structured logging
|
|
38
|
+
- **`KeyedAsyncCache<P, V, E>`**: Cache for async operations
|
|
39
|
+
|
|
40
|
+
### Vue Module (`unwrapped/vue`)
|
|
41
|
+
|
|
42
|
+
- **Composables**: `useAsyncResultRef`, `useAction`, `useLazyAction`, `useReactiveChain`, `useGenerator`, `useLazyGenerator`, `useReactiveGenerator`
|
|
43
|
+
- **Components**: `AsyncResultLoader`, `buildCustomAsyncResultLoader`
|
|
44
|
+
|
|
22
45
|
|
|
23
46
|
## Core Concepts
|
|
24
47
|
|
|
@@ -825,20 +848,6 @@ Unwrapped is in very active development and a lot of features are still planned,
|
|
|
825
848
|
- Debounce on relevant utilities
|
|
826
849
|
|
|
827
850
|
|
|
828
|
-
## API Reference
|
|
829
|
-
|
|
830
|
-
### Core Module (`unwrapped/core`)
|
|
831
|
-
|
|
832
|
-
- **`Result<T, E>`**: Synchronous result type
|
|
833
|
-
- **`AsyncResult<T, E>`**: Asynchronous result with state tracking
|
|
834
|
-
- **`ErrorBase`**: Base error class with structured logging
|
|
835
|
-
- **`KeyedAsyncCache<P, V, E>`**: Cache for async operations
|
|
836
|
-
|
|
837
|
-
### Vue Module (`unwrapped/vue`)
|
|
838
|
-
|
|
839
|
-
- **Composables**: `useAsyncResultRef`, `useAction`, `useLazyAction`, `useReactiveChain`, `useGenerator`, `useLazyGenerator`, `useReactiveGenerator`
|
|
840
|
-
- **Components**: `AsyncResultLoader`, `buildCustomAsyncResultLoader`
|
|
841
|
-
|
|
842
851
|
## License
|
|
843
852
|
|
|
844
853
|
LGPL-3.0-or-later
|