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

0.0.8 • Public • Published

@lume/variable

Create and react to reactive variables.

npm install @lume/variable --save

React to changes in reactive variables

Here's an example that shows how to make a reactive variable, change the value every second, and make an automatically executed computation that logs the value of the variable to the console any time the variable changes.

import {variable, autorun} from '@lume/variable'
 
const count = variable(0)
 
setInterval(() => count(count() + 1), 1000)
 
// The function (computation) passed into autorun fires every second due to count being incremented every second.
autorun(() => {
    console.log(count())
})

This works because the autorun computation tracks which variables were used, and tracks those variables "dependencies" or requirements of the computation. When any dependency of a computation changes, the computation function will be automatically re-executed.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.0.8
    5
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.0.8
    5
  • 0.0.3
    1
  • 0.0.2
    2
  • 0.0.1
    57

Package Sidebar

Install

npm i variable

Weekly Downloads

65

Version

0.0.8

License

MIT

Unpacked Size

168 kB

Total Files

19

Last publish

Collaborators

  • trusktr