vuejs / vuex

🗃️ Centralized State Management for Vue.js.
https://vuex.vuejs.org
MIT License
28.42k stars 9.58k forks source link

Bring back `CommitOptions#silent` #2124

Open CoryDHall opened 2 years ago

CoryDHall commented 2 years ago

What problem does this feature solve?

Referencing: https://github.com/vuejs/vuex/pull/457

The domain the silent option covered is larger than the vue-devtools vuex filter provides.


Use case:

My team is developing a statically generated site with Nuxt.We have an external vendor API that returns deeply nested POJOs modeling has-and-belongs-to-many relationships.

example:

type Entry = { 
category: { 
entries: Entry[] 
} 
}

We have a dynamic module that creates a reference tree to de-dupe objects, resolve circular references, prune and refetch stale data, etc. Loading a module for a page of API results can create hundreds of commits and registrations that are not only irrelevant for day-to-day development, but express a counter-productive level of verbosity and noise. This is compounded by the (slightly unrelated issue) devtools really struggling with keeping track of state generally, and tries to cache references to dynamic modules which are not always present, causing the devtools to hang and crash.

What does the proposed API look like?

commit('SHOW_THIS');
commit('SILENCE_THIS', null, {silent: true})

Where only SHOW_THIS hits devtools/plugins. Alternatively, a configurable option in the for Mutation<S> following the Action<S> where devs can specify an object:

{
  silent: true,
  handler() {}, // <= every invocation of this is by default silent
}

And even better an option called mute or something in Module or ModuleOptions that makes silent mode the default for the whole MutationTree.