Skip to content

A library enabling JavaScript to execute arbitrary functions when the value of any global variable changes.

Notifications You must be signed in to change notification settings

Gigabyte5671/VariableListener

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Variable Listener

Allows JavaScript to execute arbitrary functions when the value of any global variable changes.

npm bundle size

Installation

To add Variable Listener to your site or project:

<script src="https://cdn.jsdelivr.net/npm/variable-listener@latest/dist/variable-listener.min.js"></script>

or

npm install variable-listener
import 'variable-listener';

Usage

Declare your global variable:

var count = 10;

Add a new listener:

window.addVariableListener('count', function (newValue) {

    console.log(newValue);

});

The callback will be triggered whenever your variable changes:

count++;

// Callback logs: 11

If you no longer want to listen to the variable, call:

window.removeVariableListener('count');

About

A library enabling JavaScript to execute arbitrary functions when the value of any global variable changes.

Topics

Resources

Stars

Watchers

Forks