From 26af497e1a3d696f2b45f32408cc82b7f12448c5 Mon Sep 17 00:00:00 2001 From: Ali Mihandoost Date: Sun, 15 Sep 2024 19:27:23 +0330 Subject: [PATCH] docs(remote-context): Update package description and README Co-authored-by: Mohammad Honarvar --- packages/remote-context/README.md | 67 +++++++++++++++++++++++++++- packages/remote-context/package.json | 2 +- 2 files changed, 66 insertions(+), 3 deletions(-) diff --git a/packages/remote-context/README.md b/packages/remote-context/README.md index 23483b09..05cde3fe 100644 --- a/packages/remote-context/README.md +++ b/packages/remote-context/README.md @@ -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. diff --git a/packages/remote-context/package.json b/packages/remote-context/package.json index 05312f79..d0deeb22 100644 --- a/packages/remote-context/package.json +++ b/packages/remote-context/package.json @@ -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 (https://ali.mihandoost.com)", "keywords": [ "context",