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

basic-signals

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

basic-signals

Experimental very basic reactive signals for JavaScript

  • 0.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Basic-signals

This project is similar to basic-streams in its purpose. The idea is to explore what kind of operations we can implement for a certain async abstraction. And to find cases where that abstraction can be usable.

Basic-streams project explores the "Stream" abstraction which is very similar to RxJS observables in the core idea, but with much simpler and limited API. While basic-signals focuses on a slightly different abstraction called "Signal" with the following differences from streams:

  • Signals are not inert. When we create a stream it does nothing until we subscribe to it, signals on other hand are more like Promises, they "activate" immediately once created. Adding or removing an observer should not affect any other observers in any way.
  • Each signal have a current value, which is always available without observing, and must always be up to date even if there are no observers. Adding or removing an observer should not affect the current value.

Signal API

Signal is an object with two methods.

get

Must return the current value of the signal. Calling get must have no side effects, for instance it must not affect observers or change the current value.

observe

Accepts an observer, and must return an unobserve function. An observer is a function which must be called with no arguments every time the current value changes. After unobserve was called, observer must not be called. Calling an unobserve second time must have no effect i.e., it must be idempotent.

console.log('Current value is:', signal.get())

const unobserve = signal.observe(() => {
  console.log('Value has changed, the new value is:', signal.get())
})

...

unobserve()

Development

npm run lobot -- --help

Run lobot commands as npm run lobot -- args...

FAQs

Package last updated on 03 Apr 2016

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