@onesy/subscription
v1.0.0
Published
Subscription method management
Downloads
332
Maintainers
Readme
Getting started
Add
yarn add @onesy/subscription
Use
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
yarn
Test
yarn test
Prod
Build
yarn build