Configs

Configs.file

Path to file where the config will be stored. By default - ./config.json

Configs.serialize

A function that will encode an object to a string. By default - JSON.stringify

Configs.unserialize

A function that will decode an object from a string. By default - JSON.parse

Configs.autoFlush = true

Empathize has two models of working with your config files. The first and default is when all the changes save directly to the config file, so on your disk, and the second is when all the changes are saved in your application memory before you'd call Configs.flush() method to save them to your config file

This model will prevent your application from various bugs caused by several windows usage, but it also will mean that every Configs.set() call it will write some data to your disk, which is not really good, and Configs.get() will fetch configs from the disk which also means additional delay

With autoFlush = false all the config changes will be stored in your application's memory. To save these changes to the disk you'll need to call Configs.flush() method. This model will highly increase overall performance, but also requires you to develop your application carefully, so different windows will flush their config changes properly

Configs.get(name)

import { Configs } from '@empathize/framework';

// Some config
Configs.get('example_config').then((value) => {
    console.log(`Value: ${value}`);
});

// All the configs
Configs.get().then((config) => {
    for (const key of Object.keys(config))
        console.log(`${key}: ${config[key]}`);
});

Configs.set(name, value)

import { Configs } from '@empathize/framework';

Configs.set('example.config', {
    example_field: 'example value'
});

Configs.remove(name)

import { Configs } from '@empathize/framework';

Configs.remove('example.config');

Configs.defaults(configs)

import { Configs } from '@empathize/framework';

// Set default config values
Configs.defaults({
    example: {
        value_1: 1,
        value_2: 2
    },
    value_3: 3
});

Configs.flush()

Saves config from the application's memory to the disk

import { Configs } from '@empathize/framework';

Configs.flush();

Configs.load()

Loads config from the disk to the application's memory. Uses to load configs changes from another window, because all the windows have separate memories, and changes in one window will be unavailable in another

import { Configs } from '@empathize/framework';

Configs.load();

Last updated