JSPM

  • Created
  • Published
  • Downloads 37
  • Score
    100M100P100Q49361F
  • License MIT

Create and react to reactive variables.

Package Exports

  • @lume/variable
  • @lume/variable/dist/dom
  • @lume/variable/dist/html

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@lume/variable) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@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.