1.0.15 • Published 10 months ago
reactive-light v1.0.15
reactive-light
reactive-light is a lightweight JavaScript reactivity system.
Installation
npm install reactive-light
or
yarn add reactive-light
Usage
import { ref, computed, reactive, watch, watchEffect } from 'reactive-light'; // in browser
const { ref, computed, reactive, watch, watchEffect } = require('reactive-light'); // Node.js
const counter = ref(0);
const twoTimesCounter = computed(() => counter.value * 2);
watchEffect(() => {
console.log('2 * counter =', twoTimesCounter.value);
});
setInterval(() => { counter.value++; }, 1000);
const state = reactive({
msg: 'hello, world!'
});
watch(
() => state.msg,
(newMsg, oldMsg) => console.log('message changed!')
);
setTimeout(() => { state.msg = 'new message!'; }, 5000);
// Unsubscribe the watcher by calling the unsubscriber returned by watch()
const unwatch = watch(
() => state.msg,
(newMsg, oldMsg) => console.log('message changed!')
);
setTimeout(() => { unwatch(); }, 5000);
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.