1.0.27 • Published 5 years ago

@hoda5/tracker v1.0.27

Weekly downloads
1
License
ISC
Repository
github
Last release
5 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

5 years ago

1.0.26

5 years ago

1.0.25

6 years ago

1.0.24

6 years ago

1.0.23

6 years ago

1.0.22

7 years ago

1.0.21

7 years ago

1.0.20

7 years ago

1.0.19

7 years ago

1.0.18

7 years ago

1.0.17

7 years ago

1.0.16

7 years ago

1.0.15

7 years ago

1.0.14

7 years ago

1.0.13

7 years ago

1.0.12

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago