@lowlighter/reactive

3.0.4 • Public • Published

🎯 Reactivity

JSR JSR Score NPM Coverage

Track get, set, delete and call operations on objects.

📑 Examples

import { Context } from "./context.ts"

const context = new Context({ foo: "bar", bar: () => null })

// Attach listeners
context.addEventListener("get", ({ detail: { property } }: any) => console.log(`get: ${property}`))
context.addEventListener("set", ({ detail: { property, value } }: any) => console.log(`set: ${property}: ${value.old} => ${value.new}`))
context.addEventListener("delete", ({ detail: { property } }: any) => console.log(`delete: ${property}`))
context.addEventListener("call", ({ detail: { property, args } }: any) => console.log(`call: ${property}(${args.join(", ")})`))
context.addEventListener("change", ({ detail: { type } }: any) => console.log(`change: ${type}`))

// Operate on the context
context.target.foo = "baz" // Triggers the "set" and "change" events
context.target.bar() // Triggers the "call" and "change" events

✨ Features

  • Support change event for convenience.
  • Applies recursively!
  • Supports inherited context.

📜 License

Copyright (c) Simon Lecoq <@lowlighter>. (MIT License)
https://github.com/lowlighter/libs/blob/main/LICENSE

Package Sidebar

Install

npm i @lowlighter/reactive

Weekly Downloads

2

Version

3.0.4

License

MIT

Unpacked Size

56.8 kB

Total Files

10

Last publish

Collaborators

  • lowlighter