Skip to content

Commit

Permalink
docs(remote-context): Update package description and README
Browse files Browse the repository at this point in the history
Co-authored-by: Mohammad Honarvar <[email protected]>
  • Loading branch information
alimd and mohammadhonarvar committed Sep 15, 2024
1 parent 78b25d8 commit 26af497
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 3 deletions.
67 changes: 65 additions & 2 deletions packages/remote-context/README.md
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.
2 changes: 1 addition & 1 deletion packages/remote-context/package.json
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",
Expand Down

0 comments on commit 26af497

Please sign in to comment.