0.1.2 • Published 6 years ago
Syncfig
Usage:
const { SyncedConfig } = require("syncfig");
// Create a new SyncedConfig class with the path to your (JSON) config File
const syncedConfig = new SyncedConfig("./test.json");
await syncedConfig.listen();
// test.json currently contains: '{}'
syncedConfig.getConfig(); // {}
syncedConfig.setConfig({
foo: "bar"
});
/* test.json now contains:
* {
* "foo": "bar"
* }
*/
syncedConfig.getConfig(); // { foo: 'bar' }
Reacting to events regarding the file:
...
function callBack() {
console.log('The File has been changed. YAAY!');
}
syncedConfig.on('change', callBack);
Event Overview
Will results in these event (chronological order)
When the local file updates
Eventname | Descriptions |
---|
beforeChange | Emitted when the local file changes. |
afterChange | Emitted after the config object has been updated |
When the config object is updated
Eventname | Descriptions |
---|
beforeSet | Emitted before the the config object has been changed programmaticaly |
afterSet | Emitted after the the config object has been changed programmaticaly, but wasnt saved to a file yet |
beforeWrite | Emitted before the the config object changes are written to the file |
afterWrite | Emitted after the the config object changes are written to the file |
afterSet | Emitted after the the config object has been changed programmaticaly and all changes are written to the file |
Misc
Stop Watching the file (can not be restarted)
const syncedConfig = new SyncedConfig("./test.json");
syncedConfig.stopWatching();