1.0.0 • Published 1 year ago
@readytogo/global v1.0.0
readytogo-global
Store and retrieve global data
Usage
import { getGlobal, executeOnce } from '@readytogo/global';
let textField = getGlobal('textField', 'initial value');
textField = getGlobal('textField', 'secondary value');
executeOnce('printValue', () => {
console.log(textField.getValue());
textField.setValue('new value');
console.log(textField.getValue());
});
$ node example.js
initial value
new value
Note
getGlobal() will always return the instance associated with the unique key. The initial value will only be set if the value has never been set before. executeOnce() will only execute the callback function one time per unique key. To execute the same callback function again, the unique key must be different. In the usage above, the 'secondary value' will never be set or printed because the initial value has already been set before.
1.0.0
1 year ago