function createStore(initialState) {

  // Initial state tree
  let currentState = initialState || {};

  // An array of functions to invoke when state is changed; observables
  const currentListeners = [];

  // Localstorage check
  const useLocalStorage = localStorageAvailable();
  const storageKey = 'NexGenState';

  // Load state from previous session
  if (useLocalStorage && localStorage.getItem(storageKey)) {
    currentState = JSON.parse(localStorage.getItem(storageKey));
  }

  // Return the state of this store
  function getState() {
    return currentState;
  }

  // Will update the state and trigger all listener callbacks
  function setState(newState, options) {

    // Merge the new state into the current state non-destructively
    currentState = Object.assign({}, currentState, newState);

    // Persist to localStorage
    if (useLocalStorage) {
      localStorage.setItem(storageKey, JSON.stringify(currentState));
    }

    if (options && options.suppressUpdate === true) {
      return;
    }

    // Copy the listeners to avoid mutation during iteration
    const listeners = currentListeners;

    for (let i = 0; i < listeners.length; i++) { // eslint-disable-line no-plusplus

      // Invoke the listener function
      listeners[i]();
    }
  }

  // Will add the listener function to a list of functions that will trigger whenever state changes
  function subscribe(listener) {
    if (typeof listener !== 'function') {
      throw new Error('subscribe: listener is not a valid function');
    }

    currentListeners.push(listener);
  }

  return {
    getState,
    setState,
    subscribe,
  };
}
/**
 * This will return an object with a few functions for managing global
 * application state as well as subscribers to trigger when that state changes
 */
This will return an object with a few functions for managing global
application state as well as subscribers to trigger when that state changes
This will return an object with a few functions for managing global application state as well as subscribers to trigger when that state changes
function createStore(initialState) {
  let currentState = initialState || {};
  const currentListeners = [];
  const useLocalStorage = localStorageAvailable();
  const storageKey = 'NexGenState';
  if (useLocalStorage && localStorage.getItem(storageKey)) {
    currentState = JSON.parse(localStorage.getItem(storageKey));
  }
  function getState() {
    return currentState;
  }
  function setState(newState, options) {
    currentState = Object.assign({}, currentState, newState);
    if (useLocalStorage) {
      localStorage.setItem(storageKey, JSON.stringify(currentState));
    }
    if (options && options.suppressUpdate === true) {
      return;
    }
    const listeners = currentListeners;
    for (let i = 0; i < listeners.length; i++) { 
      listeners[i]();
    }
  }
  function subscribe(listener) {
    if (typeof listener !== 'function') {
      throw new Error('subscribe: listener is not a valid function');
    }
    currentListeners.push(listener);
  }
  return {
    getState,
    setState,
    subscribe,
  };
}
function createStore ( initialState ) { let currentState = initialState || { } ; const currentListeners = [ ] ; const useLocalStorage = localStorageAvailable ( ) ; const storageKey = 'NexGenState' ; if ( useLocalStorage && localStorage . getItem ( storageKey ) ) { currentState = JSON . parse ( localStorage . getItem ( storageKey ) ) ; } function getState ( ) { return currentState ; } function setState ( newState , options ) { currentState = Object . assign ( { } , currentState , newState ) ; if ( useLocalStorage ) { localStorage . setItem ( storageKey , JSON . stringify ( currentState ) ) ; } if ( options && options . suppressUpdate === true ) { return ; } const listeners = currentListeners ; for ( let i = 0 ; i < listeners . length ; i ++ ) { listeners [ i ] ( ) ; } } function subscribe ( listener ) { if ( typeof listener !== 'function' ) { throw new Error ( 'subscribe: listener is not a valid function' ) ; } currentListeners . push ( listener ) ; } return { getState , setState , subscribe , } ; }
This will return an object with a few functions for managing global
 application state as well as subscribers to trigger when that state changes
This will return an object with a few functions for managing global application state as well as subscribers to trigger when that state changes
// Initial state tree // An array of functions to invoke when state is changed; observables // Localstorage check // Load state from previous session // Return the state of this store // Will update the state and trigger all listener callbacks // Merge the new state into the current state non-destructively // Persist to localStorage // Copy the listeners to avoid mutation during iteration // eslint-disable-line no-plusplus // Invoke the listener function // Will add the listener function to a list of functions that will trigger whenever state changes