Skip to content

Instantly share code, notes, and snippets.

@luistak
Created January 27, 2021 15:45
Show Gist options
  • Save luistak/e3cb74c500f5804f3d2c80b796448fcc to your computer and use it in GitHub Desktop.
Save luistak/e3cb74c500f5804f3d2c80b796448fcc to your computer and use it in GitHub Desktop.
import { Observable } from 'windowed-observable';
// Define a specific context namespace
const observable = new Observable('cart-items');
const observer = (item) => console.log(item);
// Add an observer subscribing to new events on this observable
observable.subscribe(observer)
// Unsubscribing
observable.unsubscribe(observer);
...
// On the publisher part of the app
const observable = new Observable('cart-items');
observable.publish({ id: 1234, name: 'Mouse Gamer XyZ', quantity: 1 });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment