Socket
Socket
Sign inDemoInstall

@reactively/decorate

Package Overview
Dependencies
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@reactively/decorate

Reactively is a library for fine grained reactive programming.


Version published
Weekly downloads
0
decreased by-100%
Maintainers
2
Weekly downloads
 
Created
Source

Reactively

Reactively is a library for fine grained reactive programming.

See documentation for details.

This part of the library (@reactively/decorate) contains annotations for using reactively in classes.

/* A lightweight reactive program can look almost like regular javascript programming.
 *
 * This example uses a class, with a few @reactive annotations added.
 * (Reactively can be used without classes too)
 *
 * Here's the dataflow relationship between the reactive parts:
 *    size -> bufferBlocks -> buffer
 */
class ResizeableBuffer extends HasReactive {
  @reactively size = 0;
  @reactively get blocks() { return Math.ceil(this.size / 2 ** 12); }
  @reactively get buffer(): any {
    const newBuf = Buffer.allocUnsafe(this.blocks * 2 ** 12);
    this._buf && newBuf.copy(this._buf);
    return (this._buf = newBuf);
  }
  private _buf: any;
}

const b = new ResizeableBuffer();
b.size = 10 ** 5;

/* Here we call buffer() twice. In an imperative system we'd allocate twice
 * which is inefficient. A reactive system will allocate only once.  */
b.buffer.fill(-1);
b.buffer.setAt(0, 100);

/* A reactive system can find other efficiencies. Here's one example: */

b.size += 1; // grow the number of elements, but blocks doesn't change
b.buffer; // no new buffer allocated here!

FAQs

Package last updated on 20 Mar 2023

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