-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(remote-context): Update package description and README
Co-authored-by: Mohammad Honarvar <[email protected]>
- Loading branch information
1 parent
78b25d8
commit 26af497
Showing
2 changed files
with
66 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,66 @@ | ||
# Alwatr Server Context - `@alwatr/server-context` | ||
# @alwatr/remote-context | ||
|
||
Elegant powerful server-context manager base on alwatr signal, written in tiny TypeScript, ES module. | ||
A powerful TypeScript library for managing remote context data with offline-first support and automatic revalidation. | ||
|
||
## Features | ||
|
||
* **Offline-First:** Prioritizes cached data for a seamless user experience even without a network connection. | ||
* **Automatic Revalidation:** Keeps your context up-to-date by intelligently fetching fresh data from the server. | ||
* **State Management:** Built-in state machine tracks the context's lifecycle (initial, loading, offline check, etc.). | ||
* **TypeScript Support:** Written in TypeScript with full type definitions for improved code quality and developer experience. | ||
* **Customizable:** Extend the base class to tailor behavior to your specific needs. | ||
* **Built-in Logging:** Integrated logging for debugging and monitoring context updates. | ||
|
||
## Installation | ||
|
||
```bash | ||
npm install @alwatr/remote-context | ||
``` | ||
|
||
## Usage | ||
|
||
```typescript | ||
import {AlwatrRemoteContextStateMachine} from '@alwatr/remote-context'; | ||
|
||
const myContext = new AlwatrRemoteContextStateMachine<{data: string[]}>({ | ||
name: 'my-context', | ||
url: '/api/context', | ||
method: 'GET', | ||
}); | ||
|
||
// Trigger initial fetch (will attempt to use cache first) | ||
myContext.request(); | ||
|
||
// Access the context (may be cached or freshly fetched) | ||
console.log('Current context:', myContext.context); | ||
|
||
// Subscribe to context updates | ||
myContext.subscribe(({state, context}) => { | ||
if (state === 'complete') { | ||
console.log('Updated context:', context); | ||
} else if (state === 'failed') { | ||
console.error('Context fetch failed!'); | ||
} | ||
}); | ||
``` | ||
|
||
## API | ||
|
||
### Core Classes | ||
|
||
* **`AlwatrRemoteContextStateMachineBase`** | ||
* Base class providing core functionality for managing remote context with offline support and revalidation. | ||
* Extend this class to create custom context state machines with additional states or events. | ||
|
||
* **`AlwatrRemoteContextStateMachine`** | ||
* Concrete implementation for fetching and managing remote context data. | ||
* Provides access to `state` and `context`. | ||
* Handles offline checks, automatic revalidation, and state transitions. | ||
|
||
## Contributing | ||
|
||
Contributions are welcome! Please read the contributing guidelines before submitting a pull request. | ||
|
||
## License | ||
|
||
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"name": "@alwatr/remote-context", | ||
"version": "1.2.6", | ||
"description": "Elegant powerful context manager base on alwatr signal, written in tiny TypeScript, ES module.", | ||
"description": "A powerful TypeScript library for managing remote context data with offline-first support and automatic revalidation.", | ||
"author": "S. Ali Mihandoost <[email protected]> (https://ali.mihandoost.com)", | ||
"keywords": [ | ||
"context", | ||
|