Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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: 9 days ago
JSON representation

Subscription methods management

Awesome Lists containing this project

README

        



onesy logo

onesy 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 @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
```