export interface Action {
  type: string
  priority: number
}

export function adjustAction(actions: Action[], type: string, v: number, inc?: boolean): Action[] {
  let action = actions.find(v=>v.type===type)
  if (!action) {
    if (v === 0) return actions
    actions.push({
      type: type,
      priority: v,
    })
  } else {
    action.priority = inc?action.priority+v:v
    if (action.priority <= 0) {
      actions = actions.filter(v=>v!==action)
    }
  }
  return actions
}
