Comments (12)
Is it possible get rid of strings when calling mutation inside action this.context.commit('addWheel', wheels)
and call class method like this.mutations.addWheel(wheels)
?
from vuex-module-decorators.
Have you implemented this yet?
from vuex-module-decorators.
No, still figuring out what would be the best way to handle this.
from vuex-module-decorators.
Just replace field with getter/setter on @mutable annotation(decorator)?
from vuex-module-decorators.
For example
@Mutable
data:any;
from vuex-module-decorators.
Hmmm that sounds pretty good!
from vuex-module-decorators.
@championswimmer it’d be less powerful than supporting something like this though:
class Example {
set INITIALIZE({ id, firstName, lastName }: User) {
this.id = id
this.firstName = firstName
this.lastName = lastName
}
}
Another advantage would be that this is a lot closer to the normal vuex
behavior.
from vuex-module-decorators.
Can you please give a full example of getter/setter with @mutable decoration?
Can it be used in current released?
from vuex-module-decorators.
@Koc That would be great, right now refactoring large stores is more tedious than it needs to be with the strings....
from vuex-module-decorators.
I would love simple @Mutable
like @talkid134 suggests. I have lots of simple data members in the state -- right now each one needs a mutation to set its value. (Well I suppose I could have one uber-mutation that took the string name of the prop to update... but that would be ugly.)
from vuex-module-decorators.
Is it possible get rid of strings when calling mutation inside action
this.context.commit('addWheel', wheels)
and call class method likethis.mutations.addWheel(wheels)
?
@Koc @douglasg14b I "get rid" of strings by adapting the Vuex mutation name convention
const rawError = true
const setPage = 'setPage'
@Module
export default class ActivitiesModule extends VuexModule {
page: Page<OperationDTO> = {
totalElements: 0,
content: []
}
@Mutation [setPage] (value: ActivitiesModule['page']) { this.page = value }
@Mutation cleanPage () { this.page = { totalElements: 0, content: [] }
@Action({ rawError })
async pullPage (/*...*/) {
const response = await operationService
.getByFinancialAccount_IdAndOccurrenceDateBetween(/*...*/)
// use this:
this.context.commit(setPage, response.data)
// instead of this:
this.context.commit('setPage', response.data)
}
}
The mutation function will stop appearing in vscode's autocomplete when using getModule, because it's a computed property name, but parameter hints and type-checking still work.
Update: you can also ditch the constant and use the class prototype instead:
Update 2: This doesn't work on production builds. ↓↓↓ For some odd reason, all .name
props inside mutatation method prototypes return the string "value"
when it's built with Vue CLI 3 npm run build
.
const rawError = true
@Module
export default class ActivitiesModule extends VuexModule {
page: Page<OperationDTO> = {
totalElements: 0,
content: []
}
@Mutation setPage (value: ActivitiesModule['page']) { this.page = value }
@Mutation cleanPage () { this.page = { totalElements: 0, content: [] }
@Action({ rawError })
async pullPage (/*...*/) {
const response = await operationService
.getByFinancialAccount_IdAndOccurrenceDateBetween(/*...*/)
// DONT DO THIS ↓, IT WILL LIKELY BREAK IN PRODUCTION
this.context.commit(ActivitiesModule.prototype.setPage.name, response.data)
}
}
from vuex-module-decorators.
As a "workaround", I use vuex-module-decorators
along with Pathify:
import { VuexModule, Module } from 'vuex-module-decorators'
import { make } from 'vuex-pathify'
@Module
class Preferences extends VuexModule {
grid = {
editable: false,
textOnHover: false,
textHoverTimeout: 1000,
}
}
Preferences.mutations = {
...make.mutations(Preferences.state),
...Preferences.mutations
}
export default Preferences
And in my component, I use get()
, set()
and sync()
from pathify.
from vuex-module-decorators.
Related Issues (20)
- MutationAction not working with RemoteData union type
- got error when use @Mutation in app.config.errorHandler HOT 2
- MutationAction not having access to module state? HOT 5
- How can I split up an module-class HOT 1
- Conflict with NuxtJS third-party modules HOT 2
- When will you release the new version ?
- MutationAction still not works HOT 2
- peer vuex@"3" from [email protected] HOT 3
- Setting an object through MutateAction throws an exception HOT 3
- Action method question HOT 1
- Missing github release and changelog for v2 HOT 2
- v2.0.0 there are any breaking changes ? HOT 2
- Can vite hot update be supported?
- How can I use Try catch inside @MutationAction?
- in @Mutation,this is undefined HOT 1
- In @Mutation, how to call another Mutation, this.xxx is undefined HOT 1
- vue.reactive is not a function (Nuxtjs, Typescript)
- MutationAction never commits changes, if component switched
- Using vuex-module-decorators with vue2 HOT 1
- fix: support typescript 4.8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vuex-module-decorators.