Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@alwatr/observable

Package Overview
Dependencies
Maintainers
0
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@alwatr/observable

A lightweight and flexible TypeScript library for implementing the observer pattern (similar to signals) with events, subscriptions, and convenient features.

  • 4.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
107
decreased by-7.76%
Maintainers
0
Weekly downloads
 
Created
Source

Flux: Observable

A lightweight and flexible TypeScript library for implementing the observer pattern (similar to signals) with events, subscriptions, and convenient features.

Features

  • Simple and Intuitive: Easy-to-use API for subscribing to and emitting events.
  • TypeScript Support: Written in TypeScript with full type definitions for improved code quality and developer experience.
  • Flexible Options: Control subscription behavior with options like once, priority, and receivePrevious.
  • Asynchronous Support: Handle asynchronous events with Promise-based callbacks.
  • Built-in Logging: Integrated logging for debugging and monitoring.

Installation

npm install @alwatr/observable

API

AlwatrObservable

  • constructor(config: {name: string; loggerPrefix?: string}): Creates a new AlwatrObservable instance.

    • config.name: The name of the signal (used for logging).
    • config.loggerPrefix: Optional prefix for log messages.
  • subscribe(listenerCallback: ListenerCallback<this, T>, options: SubscribeOptions = {}): SubscribeResult: Subscribes to the signal.

    • listenerCallback: The function to be called when an event is emitted.
    • options:
      • once: If true, the listener will be automatically unsubscribed after the first event.
      • priority: If true, the listener will be executed before other listeners.
      • receivePrevious: If true, the listener will be immediately called with the last emitted event (if available).
      • disabled: If true, the listener will not be executed.
  • unsubscribe(listenerCallback: ListenerCallback<this, T>): Unsubscribes a listener from the signal.

  • notify_(message: T): Emits an event to all subscribers.

    • message: The data to be sent to the subscribers.
  • clearMessage_(): Clears the current message without notifying subscribers.

  • untilNewNotify_(): Returns a Promise that resolves with the next emitted event.

Sponsors

The following companies, organizations, and individuals support flux ongoing maintenance and development. Become a Sponsor to get your logo on our README and website.

Exir Studio

Contributing

Contributions are welcome! Please read our contribution guidelines before submitting a pull request.

License

This project is licensed under the AGPL-3.0 License.

Keywords

FAQs

Package last updated on 06 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc