8000 GitHub - hlehmann/reactivityjs · GitHub
[go: up one dir, main page]

Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Repository files navigation

Reactivity.js

GitHub branch checks state Codecov GitHub

Concepts

  • Source: a "watchable" version of an object
  • Watcher: a readonly object that detect read data and subscribe for any change

Basic example

// define sources

const userSource = getSource({
  name: "John",
  parent: { name: "Henry" },
});

// watch sources

runner((watch) => {
  const user = watch(userSource);
  document.getElementById("user-name").textContent = user.name;
});

const Component = () => {
  const user = useWatch(userSource);
  return <div>{user.parent.name}</div>;
};

// update sources

userSource.parent.name = "Tim";
user.$source.parent.name = "Tim";

How it works

  • It uses Proxy to detect read fields and updated fields.
  • It uses WeakMap and WeakRef to make efficient subscriptions.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages

0