Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/amaui-org/amaui-subscription
Subscription methods management
https://github.com/amaui-org/amaui-subscription
amaui back-end backend browser front-end frontend javascript js library node nodejs sub subscription subscriptions typescript utils web
Last synced: about 2 months ago
JSON representation
Subscription methods management
- Host: GitHub
- URL: https://github.com/amaui-org/amaui-subscription
- Owner: amaui-org
- License: mit
- Created: 2022-02-01T00:44:44.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-03-29T22:27:30.000Z (9 months ago)
- Last Synced: 2024-09-23T04:18:14.637Z (3 months ago)
- Topics: amaui, back-end, backend, browser, front-end, frontend, javascript, js, library, node, nodejs, sub, subscription, subscriptions, typescript, utils, web
- Language: TypeScript
- Homepage: https://docs.amaui.me/library/subscription
- Size: 519 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
amaui Subscription
Subscription methods management
MIT license
Production ready
UMD 2.7kb gzipped
100% test cov
Browser and Nodejs
Very simple code
Modern code
Junior friendly
Typescript
Made with :yellow_heart:
## Getting started
### Add
```sh
yarn add @amaui/subscription
```### Use
```javascript
import AmauiSubscription from '@amaui/subscription';// Make a new subscription instance
// with an optional initial value
const amauiSub = new AmauiSubscription('🙂');// Value
amauiSub.value;// '🙂'
const method = (...value) => console.log('Yup, I got it ', ...value);
const method1 = value => console.log('Yup, I got it as well ', value);
// Methods subscribe
amauiSub.subscribe(method);amauiSub.subscribe(method1);
// Emit a value to all subscribed methods
// a value always emitted as arguments received by emit method
amauiSub.emit('🌱', '🌱', '🌱', '🌱');// method, log:
// Yup, I got it 🌱 🌱 🌱 🌱// method1, log:
// Yup, I got it as well 🌱// Methods unsubscribe
amauiSub.unsubscribe(method);amauiSub.unsubscribe(method1);
// or with anonymous method
const subscription = amauiSub.subscribe(value => console.log(value));subscription.unsubscribe();
```### Dev
Install
```sh
yarn
```Test
```sh
yarn test
```### Prod
Build
```sh
yarn build
```