1.0.15 • Published 10 months ago

reactive-light v1.0.15

Weekly downloads
2
License
MIT
Repository
github
Last release
10 months ago

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.

License

MIT

1.0.15

10 months ago

1.0.14

10 months ago

1.0.13

10 months ago

1.0.12

10 months ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.2

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago