Sawtaytoes
4/25/2019 - 3:50 AM

AngularJS Redux Dispatch

var actions = {
  UPDATE_IDS: function(action) {
    vm.ids = action.ids
  },
  UPDATE_PRIVILAGES: function(action) {
    vm.privileges = action.privileges
  },
}

var dispatch = function(
  action,
) {
  if (!action.type) {
    console
    .error(
        "No type for action",
        action,
    )
  }

  if (window.__isDebugging) {
    console
    .info(
      action.type,
      action,
    )
  }

  actions[action.type]
  && actions[action.type](action)

  return action
}

var vm = this

vm.onClick = function() {
  idsService
  .get()
  .then(function(ids) {
    dispatch({
      ids: ids,
      type: 'UPDATE_IDS',
    })
  })
}