https://github.com/onesy-me/subscription
Subscription methods management
https://github.com/onesy-me/subscription
amaui back-end backend browser front-end frontend javascript js library node nodejs sub subscription subscriptions typescript utils web
Last synced: 3 months ago
JSON representation
Subscription methods management
- Host: GitHub
- URL: https://github.com/onesy-me/subscription
- Owner: onesy-me
- License: mit
- Created: 2022-02-01T00:44:44.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2025-09-29T20:37:43.000Z (9 months ago)
- Last Synced: 2025-10-05T10:26:17.572Z (9 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.onesy.me/library/subscription
- Size: 649 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
onesy Subscription
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:
### Add
```sh
yarn add @onesy/subscription
```
### Use
```javascript
import OnesySubscription from '@onesy/subscription';
// Make a new subscription instance
// with an optional initial value
const onesySub = new OnesySubscription('🙂');
// Value
onesySub.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
onesySub.subscribe(method);
onesySub.subscribe(method1);
// Emit a value to all subscribed methods
// a value always emitted as arguments received by emit method
onesySub.emit('🌱', '🌱', '🌱', '🌱');
// method, log:
// Yup, I got it 🌱 🌱 🌱 🌱
// method1, log:
// Yup, I got it as well 🌱
// Methods unsubscribe
onesySub.unsubscribe(method);
onesySub.unsubscribe(method1);
// or with anonymous method
const subscription = onesySub.subscribe(value => console.log(value));
subscription.unsubscribe();
```
### Dev
Install
```sh
yarn
```
Test
```sh
yarn test
```
### Prod
Build
```sh
yarn build
```