/**
* ### State management library
*
* All functions that are related to state management
*
* State as a singleton can be accessed anywhere in the application by a simple
* require, making it very simple to check the current state.
* State should be the ONLY mutated object in the app. Its properties will be
* replaced by updated ones over and over again during the app lifecycle,
* ensuring that all functions remain pure.
*
* @module Library/State
*/
"use strict";
const {
get,
has,
set
} = require("lodash");
/**
* State getter
* @param {String} path - Path to retrieve
* @return {Any} Value located at path in this module
*/
exports.get = (path) => get(exports, path);
/**
* State setter
* @param {String} path - Path to create/update
* @param {Any} value - Value to create/update
* @return {Void} Nothing
*/
exports.set = (path) => function(value) {
set(exports, path, value);
};
/**
* State updater (only set if the property already exists)
* @param {String} path - Path to update
* @param {Any} value - Value to update with
* @return {Void} Nothing
*/
exports.update = (path) => (value) => has(exports, path) && exports.set(path)(value);