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

@thi.ng/atom

Package Overview
Dependencies
Maintainers
1
Versions
241
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@thi.ng/atom

Mutable wrapper for a immutable values

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.1K
increased by123.71%
Maintainers
1
Weekly downloads
 
Created
Source

@thi.ng/atom

npm (scoped)

About

Clojure inspired mutable wrappers for (usually) immutable values, with support for watches.

TODO

Installation

yarn add @thi.ng/atom

Usage examples

Atom

import * as atom from "@thi.ng/atom";

const a = new atom.Atom(23);

// obtain value via deref()
a.deref();
// 23

// add watch to observe value changes
a.addWatch("foo", (id, prev, curr) => console.log(`${id}: ${prev} -> ${curr}`));
// true

a.swap((val)=> val + 1);
// foo: 23 -> 24

a.reset(42);
// foo: 24 -> 42

Cursor

// main state
main = new atom.Atom({a: 23, b: 42});

// cursor to `a` value
// requires both a lookup & update function to given value
// both fns will be called with cursor's parent state
// the updater MUST NOT mutate in place
cursor = new atom.Cursor(main, (state) => state.a, (state, x) => ({...state, a: x}));

// add watch just as with Atom
cursor.addWatch("foo", console.log);

cursor.deref()
// 23

cursor.swap(x => x + 1);
// foo 23 24

main.deref()
// { a: 24, b: 42 }

Authors

  • Karsten Schmidt

License

© 2018 Karsten Schmidt // Apache Software License 2.0

Keywords

FAQs

Package last updated on 29 Jan 2018

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