Package Exports
- @amaui/subscription
- @amaui/subscription/esm/index.js
- @amaui/subscription/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@amaui/subscription) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
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 💛
Getting started
Add
yarn add @amaui/subscriptionUse
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
yarnTest
yarn testProd
Build
yarn build