/watch-state-mixer

A tool to mix usual variables with state

Primary LanguageTypeScriptMIT LicenseMIT

@watch-state/mixer

NPM downloads license
Mixer is a tool to mix usual variables with state

Installation

npm

npm i @watch-state/mixer

yarn

yarn add @watch-state/mixer

Or just download a minified js file here

Using

Mixer works like Cache but you can mix some states and usual variables.

let count = 0

const text = new Mixer(() => {
  return count++ ? (
    `Updated: ${count - 1}`
  ) : null
})

const watcher = new Watch(() => {
  console.log(
    text.value ? text.value : 'First render'
  )
})
// console.log('First render')

watcher.update()
// console.log('Updated: 1')

watcher.update()
// console.log('Updated: 2')

you cannot use mixer inside cache, it'll be fixed in the future

Issues

If you find a bug or have a suggestion, please file an issue on GitHub.
issues


stars watchers