1.0.27 • Published 4 years ago

@hoda5/tracker v1.0.27

Weekly downloads
1
License
ISC
Repository
github
Last release
4 years ago

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

1.0.27

4 years ago

1.0.26

4 years ago

1.0.25

5 years ago

1.0.24

5 years ago

1.0.23

5 years ago

1.0.22

5 years ago

1.0.21

6 years ago

1.0.20

6 years ago

1.0.19

6 years ago

1.0.18

6 years ago

1.0.17

6 years ago

1.0.16

6 years ago

1.0.15

6 years ago

1.0.14

6 years ago

1.0.13

6 years ago

1.0.12

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago