valoo
TypeScript icon, indicating that this package has built-in type declarations

2.1.0Ā ā€¢Ā PublicĀ ā€¢Ā Published

šŸ» valoo

just the bare necessities of state management.

Usage

Hotlink it from https://unpkg.com/valoo.

See Interactive Codepen Demo.

importĀ valooĀ fromĀ 'https://unpkg.com/valoo'
Ā 
//Ā createĀ anĀ observableĀ value:
constĀ numĀ =Ā valoo(42)
Ā 
//Ā subscribeĀ toĀ valueĀ changes:
constĀ offĀ =Ā num.on(Ā vĀ =>Ā console.log(v)Ā )
Ā 
//Ā unsubscribeĀ thatĀ listener:
off()
Ā 
//Ā setĀ theĀ value,Ā invokingĀ anyĀ listeners:
num(43)
Ā 
//Ā getĀ theĀ currentĀ value:
num()Ā Ā //Ā 43

Other Versions

  • valoo-lite.mjs: lighter 120b version, but doesn't support unsubscribing.
  • valoo-original.mjs: v1-compatible, with subscribe handled via overloading.

Credit

The idea here was first implemented in Mithril. I believe the subscription mechanism is new though.

License

Apache-2.0. Copyright 2018 Google LLC.

Dependentsā€‚(1)

Package Sidebar

Install

npm i valoo

Weekly Downloads

41

Version

2.1.0

License

Apache-2.0

Unpacked Size

5.81 kB

Total Files

13

Last publish

Collaborators

  • developit