@distributedlab/reactivity
TypeScript icon, indicating that this package has built-in type declarations

1.0.0-rc.16 • Public • Published

@distributedlab/reactivity

Implementation of the reactivity connections to propagate changes between objects.

version (scoped package) types tree-shaking checks

Example

Basic usage:

import { ref, computed, toRaw } from '@distributedlab/reactivity'

const newPerson = () => {
  const age = ref(30)
  const name = computed(() => 'John')

  const changeAge = (newAge: number) => {
    age.value = newAge
  }

  return toRaw({ age, name, changeAge })
}

const john = newPerson()

console.log(john.age) // 30
console.log(john.name) // John

obj.changeAge(35)

console.log(john.age) // 35

Usage with extending:

const newHuman = () => {
  const age = ref(25)

  const changeAge = (newAge: number) => {
    age.value = newAge
  }

  return toRaw({ age, changeAge })
}

const newPerson = () => {
  const parent = newHuman()
  const name = computed(() => 'John')
  return toRaw(extend(parent, { name }))
}

const person = newPerson()

console.log(person.age) // 25

person.changeAge(30)

console.log(person.age) // 30

Changelog

For the change log, see CHANGELOG.md.

Readme

Keywords

none

Package Sidebar

Install

npm i @distributedlab/reactivity

Weekly Downloads

369

Version

1.0.0-rc.16

License

MIT

Unpacked Size

44.7 kB

Total Files

48

Last publish

Collaborators

  • arvolear
  • artsuslov
  • napalmpapalam
  • volendi