0.0.3 • Published 6 years ago
micro-swap v0.0.3
**
MICRO-SWAP
**
Micro library to observe changes in values
**
Installation
** Using npm:
$ npm i -S micro-swap
In Node.js:
...
const { MicroSwap } = require('micro-swap');
...
In browser:
<body>
...
<script src="node_modules/micro-swap/index.js"></script>
...
</body>
In Typescript:
...
import { MicroSwap } from 'micro-swap';
...
**
Example
**
const microSwap = new MicroSwap('initial value');
const swap1 = microSwap.swap((oldValue, newValue) => {
/* Change 1
oldValue // return 'initial value'
newValue // return 'change 1'
*/
/* Change 2
It does not issue the change, it is deactivated with UnSwap
*/
});
const swap2 = microSwap.swap((oldValue, newValue) => {
/* Change 1
oldValue // return 'initial value'
newValue // return 'change 1'
*/
/* Change 2
oldValue // return 'change 1'
newValue // return 'change 2'
*/
});
microSwap.value // return 'initial value'
microSwap.value = 'change 1'; // Change 1
swap1.unSwap(); // Cancel the swap1
microSwap.value = 'change 2'; // Change 2