1.0.5 • Published 9 months ago

@amaui/subscription v1.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

Getting started

Add

  yarn add @amaui/subscription

Use

  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

  yarn

Test

  yarn test

Prod

Build

  yarn build