New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@alwatr/context

Package Overview
Dependencies
Maintainers
0
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@alwatr/context - npm Package Compare versions

Comparing version 1.1.2 to 3.0.0

dist/main.cjs

61

CHANGELOG.md

@@ -6,60 +6,13 @@ # Change Log

## [1.1.2](https://github.com/AliMD/alwatr/compare/@alwatr/context@1.1.1...@alwatr/context@1.1.2) (2023-09-12)
## 3.0.0 (2024-09-15)
**Note:** Version bump only for package @alwatr/context
## [1.1.1](https://github.com/AliMD/alwatr/compare/@alwatr/context@1.1.0...@alwatr/context@1.1.1) (2023-09-12)
**Note:** Version bump only for package @alwatr/context
# 1.1.0 (2023-09-12)
# 1.0.0 (2023-06-14)
# 0.32.0 (2023-05-27)
### Bug Fixes
* **context:** compatible with new storage api ([5251ff0](https://github.com/AliMD/alwatr/commit/5251ff005624720e091cdbc40e6b0142743428cb))
# 0.31.0 (2023-05-08)
### Bug Fixes
* build issues ([e1060bc](https://github.com/AliMD/alwatr/commit/e1060bccbfe3c775c32b85e9b8eb601e48b2998c))
* **context:** merge request option issue ([e24e695](https://github.com/AliMD/alwatr/commit/e24e695a8c25ab1dcb1c351a3ae0434e921610d0))
* new logger api ([9d83a7d](https://github.com/AliMD/alwatr/commit/9d83a7dc5c103bc3bb4282dacfd85fa998915300))
* packages and refs ([eea2382](https://github.com/AliMD/alwatr/commit/eea2382e459ccaa3e7b4b329d9c196eda146a08e))
### Features
* **context:** add `requestIfNotComplete` ([580d5c9](https://github.com/AliMD/alwatr/commit/580d5c9c74f1c8921b45d402641df9444f438547))
* **context:** awesome server context ([c001c58](https://github.com/AliMD/alwatr/commit/c001c58a2b1b4e13fd1c34b5128031fd640a98e1))
* **context:** new package ([98ee43d](https://github.com/AliMD/alwatr/commit/98ee43d83b1ad5b3806ec6053c5cac70912000b3))
* **context:** simple context api ([2a1b152](https://github.com/AliMD/alwatr/commit/2a1b152380f267a6b173f08bbbe10295325b1fd8))
* bew package @alwatr/context ([9ee2204](https://github.com/Alwatr/flux/commit/9ee220484fd99654d1303851c2e03f2bd0b308a3)) by @AliMD
# [1.0.0](https://github.com/AliMD/alwatr/compare/v0.32.0...v1.0.0) (2023-06-14)
### Code Refactoring
**Note:** Version bump only for package @alwatr/context
# [0.32.0](https://github.com/AliMD/alwatr/compare/v0.31.0...v0.32.0) (2023-05-27)
### Bug Fixes
- **context:** compatible with new storage api ([5251ff0](https://github.com/AliMD/alwatr/commit/5251ff005624720e091cdbc40e6b0142743428cb))
# [0.31.0](https://github.com/AliMD/alwatr/compare/v0.30.0...v0.31.0) (2023-05-08)
### Bug Fixes
- build issues ([e1060bc](https://github.com/AliMD/alwatr/commit/e1060bccbfe3c775c32b85e9b8eb601e48b2998c))
- **context:** merge request option issue ([e24e695](https://github.com/AliMD/alwatr/commit/e24e695a8c25ab1dcb1c351a3ae0434e921610d0))
- new logger api ([9d83a7d](https://github.com/AliMD/alwatr/commit/9d83a7dc5c103bc3bb4282dacfd85fa998915300))
- packages and refs ([eea2382](https://github.com/AliMD/alwatr/commit/eea2382e459ccaa3e7b4b329d9c196eda146a08e))
### Features
- **context:** add `requestIfNotComplete` ([580d5c9](https://github.com/AliMD/alwatr/commit/580d5c9c74f1c8921b45d402641df9444f438547))
- **context:** awesome server context ([c001c58](https://github.com/AliMD/alwatr/commit/c001c58a2b1b4e13fd1c34b5128031fd640a98e1))
- **context:** new package ([98ee43d](https://github.com/AliMD/alwatr/commit/98ee43d83b1ad5b3806ec6053c5cac70912000b3))
- **context:** simple context api ([2a1b152](https://github.com/AliMD/alwatr/commit/2a1b152380f267a6b173f08bbbe10295325b1fd8))
* Update @alwatr/context package and add @alwatr/logger package ([54dbf86](https://github.com/Alwatr/flux/commit/54dbf86b1b503bea6d539679d4c1f5ac151d550d)) by @AliMD
* Update all package URLs to point to the flux repository ([e7e56d2](https://github.com/Alwatr/flux/commit/e7e56d252d4a0e1b4b1fa20c06e8b61b1b7242ae)) by @AliMD
* Update AlwatrContext constructor to use AlwatrObservableConfig ([c9c3637](https://github.com/Alwatr/flux/commit/c9c363768b52c426abdc29d94a82433a8473c05d)) by @AliMD
* Update package dependencies and references ([888f698](https://github.com/Alwatr/flux/commit/888f6987553a410e561da9fe21c0655f8f935db0)) by @AliMD
{
"name": "@alwatr/context",
"version": "1.1.2",
"description": "Elegant powerful context manager base on alwatr signal, written in tiny TypeScript, ES module.",
"version": "3.0.0",
"description": "A simple yet powerful TypeScript library for managing application context and facilitating efficient communication between components.",
"author": "S. Ali Mihandoost <ali.mihandoost@gmail.com>",
"keywords": [
"context",
"signal",
"observable",
"typescript",

@@ -12,9 +13,17 @@ "esm",

],
"main": "index.js",
"type": "module",
"types": "index.d.ts",
"author": "S. Ali Mihandoost <ali.mihandoost@gmail.com> (https://ali.mihandoost.com)",
"main": "./dist/main.cjs",
"module": "./dist/main.mjs",
"types": "./dist/main.d.ts",
"exports": {
".": {
"types": "./dist/main.d.ts",
"import": "./dist/main.mjs",
"require": "./dist/main.cjs"
}
},
"license": "MIT",
"files": [
"**/*.{d.ts.map,d.ts,js.map,js,html,md}"
"**/*.{js,mjs,cjs,map,d.ts,html,md}",
"!demo/**/*"
],

@@ -26,18 +35,40 @@ "publishConfig": {

"type": "git",
"url": "https://github.com/AliMD/alwatr",
"directory": "core/context"
"url": "https://github.com/Alwatr/flux",
"directory": "packages/context"
},
"homepage": "https://github.com/AliMD/alwatr/tree/main/core/context#readme",
"homepage": "https://github.com/Alwatr/flux/tree/next/packages/context#readme",
"bugs": {
"url": "https://github.com/AliMD/alwatr/issues"
"url": "https://github.com/Alwatr/flux/issues"
},
"prettier": "@alwatr/prettier-config",
"scripts": {
"b": "yarn run build",
"t": "yarn run test",
"w": "yarn run watch",
"c": "yarn run clean",
"cb": "yarn run clean && yarn run build",
"d": "yarn run build:es && yarn node --enable-source-maps --trace-warnings",
"build": "yarn run build:ts & yarn run build:es",
"build:es": "nano-build --preset=module",
"build:ts": "tsc --build",
"test": "NODE_OPTIONS=\"$NODE_OPTIONS --enable-source-maps --experimental-vm-modules\" jest",
"watch": "yarn run watch:ts & yarn run watch:es",
"watch:es": "yarn run build:es --watch",
"watch:ts": "yarn run build:ts --watch --preserveWatchOutput",
"clean": "rm -rfv dist *.tsbuildinfo"
},
"dependencies": {
"@alwatr/fetch": "^1.1.2",
"@alwatr/fsm": "^1.1.2",
"@alwatr/logger": "^1.1.2",
"@alwatr/signal": "^1.1.2",
"@alwatr/util": "^1.2.0",
"tslib": "^2.6.2"
"@alwatr/logger": "^3.2.13",
"@alwatr/observable": "^3.0.0"
},
"gitHead": "16036de8a6d781116e8c463ba41a2cb8cdc34edc"
"devDependencies": {
"@alwatr/nano-build": "^1.3.9",
"@alwatr/prettier-config": "^1.0.4",
"@alwatr/tsconfig-base": "^1.2.0",
"@alwatr/type-helper": "^1.2.6",
"@types/node": "^22.5.5",
"jest": "^29.7.0",
"typescript": "^5.6.2"
},
"gitHead": "6c8830345d35da730c386adb047ca2cdcb3c36f0"
}

@@ -1,3 +0,86 @@

# Alwatr Context - `@alwatr/context`
# @alwatr/context
Elegant powerful context manager base on alwatr signal, written in tiny TypeScript, ES module.
A simple yet powerful TypeScript library for managing application context and facilitating efficient communication between components.
## Features
* **Centralized Context:** Provides a unified location to store and access global application state.
* **Reactive Updates:** Built-in observer pattern ensures components are automatically notified when the context changes.
* **TypeScript Support:** Written in TypeScript with full type definitions for improved code quality and developer experience.
* **Intuitive API:** Easy-to-use methods for setting, getting, and clearing context values.
* **Asynchronous Handling:** `untilChange()` enables components to wait for context updates.
* **Built-in Logging:** Integrated logging for debugging and monitoring.
## Installation
```bash
npm install @alwatr/context
```
## Usage
```typescript
import {AlwatrContext} from '@alwatr/context';
// Create a new context
const userContext = new AlwatrContext<{name: string; email: string}>({name: 'user-context'});
// Set the context value
userContext.setValue({name: 'Alice', email: '[email address removed]'});
// Get the current context value
const currentUser = userContext.getValue();
console.log('Current user:', currentUser); // {name: 'Alice', email: '[email address removed]'}
// Subscribe to context changes
const subscription = userContext.subscribe((newUser) => {
console.log('User context updated:', newUser);
});
// Update the context
userContext.setValue({name: 'Bob', email: '[email address removed]'});
// Wait for the next context change asynchronously
const nextUser = await userContext.untilChange();
console.log('Next user:', nextUser);
// Unsubscribe when done
subscription.unsubscribe();
// Clear the context value
userContext.expire();
```
## API
### `AlwatrContext`
* **`constructor(config: {name: string; loggerPrefix?: string})`:** Creates a new `AlwatrContext` instance.
* `config.name`: The name of the context (used for logging).
* `config.loggerPrefix`: Optional prefix for log messages.
* **`getValue(): T | undefined`:** Gets the current context value. Returns `undefined` if the context has not been set or has expired.
* **`setValue(value: T)`:** Sets the context value and notifies all subscribers.
* **`subscribe(listenerCallback: ListenerCallback<this, T>, options: SubscribeOptions = {}): SubscribeResult`:** (Inherited from `AlwatrObservable`) Subscribes to context changes.
* `listenerCallback`: The function to be called when the context value changes.
* `options`:
* `once`: If `true`, the listener will be automatically unsubscribed after the first change.
* `priority`: If `true`, the listener will be executed before other listeners.
* `receivePrevious`: If `true`, the listener will be immediately called with the current context value (if available).
* `disabled`: If `true`, the listener will not be executed.
* **`unsubscribe(listenerCallback: ListenerCallback<this, T>)`:** (Inherited from `AlwatrObservable`) Unsubscribes a listener from context changes.
* **`expire()`:** Clears the current context value without notifying subscribers.
* **`untilChange()`:** Returns a Promise that resolves with the next context value after a change occurs.
## 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.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc