@hoda5/tracker
TypeScript icon, indicating that this package has built-in type declarations

1.0.27 • Public • Published

tracker (from Meteor)

Build Status codecov

This package is an adaptation from

npm install @hoda5/tracker
import { autorun, Dependency } from '@hoda5/tracker'

let weather = 'sunny';
const weatherDep = new Dependency;

function getWeather() {
  weatherDep.depend();
  return weather;
}

function setWeather(newWeather) {
  weather = newWeather;
  weatherDep.changed();
}

tracking with console.log

autorun( ()=> {
  const weather = getWeather();
  console.log("Weather: " + weather);
});

setTimeout( () => setWeather("rainy"), 1000);
setTimeout( () => setWeather("cloudy"), 2000);

tracking with ReactJS

const ReactiveComponent = weatherDep.rx(() => {
  const weather = getWeather();
  return (
    <span>
      Weather: <b>{weather}</b>
    </span>
  );
});

const rootElement = document.getElementById("root");
ReactDOM.render(<ReactiveComponent />, rootElement);

setTimeout( () => setWeather("rainy"), 1000);
setTimeout( () => setWeather("cloudy"), 2000);

Edit mynz7nlmwj

Readme

Keywords

none

Package Sidebar

Install

npm i @hoda5/tracker

Weekly Downloads

1

Version

1.0.27

License

ISC

Unpacked Size

67.4 kB

Total Files

11

Last publish

Collaborators

  • thr0w