
function ViewModel() {

  //private menbers
  let events = {
    onInit: function () { },
    onLoading: function () { },
  };

  //private methods
  function init() {
    events.onInit();
  }

    // Loading
    function showLoading() {
      events.onLoading(true);
    }
  
    function hideLoading() {
      events.onLoading(false);
    }

  /******************************/

  function callbackDefault() {}

  function onInit(_callback = callbackDefault) {
    events.onInit = _callback;
  }

  function onLoading(_callback = callbackDefault) {
    events.onLoading = _callback;
  }

  function onAlert(_callback = callbackDefault) {
    events.onAlert = _callback;
  }

  //constructor
  {
    console.log('ViewModel is loaded.');
  }

  //public

  return {
    init,
    onInit,
    onLoading,
    onAlert
  };
};

export default ViewModel;
window.viewModel = new ViewModel();