Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gigabyte5671/variablelistener
A library enabling JavaScript to execute arbitrary functions when the value of any global variable changes.
https://github.com/gigabyte5671/variablelistener
javascript javascript-library listener variables
Last synced: 5 days ago
JSON representation
A library enabling JavaScript to execute arbitrary functions when the value of any global variable changes.
- Host: GitHub
- URL: https://github.com/gigabyte5671/variablelistener
- Owner: Gigabyte5671
- Created: 2022-02-06T02:36:49.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-05-28T03:43:38.000Z (over 1 year ago)
- Last Synced: 2024-03-15T15:22:59.458Z (8 months ago)
- Topics: javascript, javascript-library, listener, variables
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/variable-listener
- Size: 20.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Variable Listener
Allows JavaScript to execute arbitrary functions when the value of any global variable changes.
![npm bundle size](https://img.shields.io/bundlephobia/min/variable-listener)
## Installation
To add Variable Listener to your site or project:
```html```
or
```bash
npm install variable-listener
``````javascript
import 'variable-listener';
```## Usage
Declare your global variable:
```javascript
var count = 10;
```Add a new listener:
``` javascript
window.addVariableListener('count', function (newValue) {console.log(newValue);
});
```The callback will be triggered whenever your variable changes:
```javascript
count++;// Callback logs: 11
```If you no longer want to listen to the variable, call:
``` javascript
window.removeVariableListener('count');
```