-
-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better support for Vuex strict mode #92
Comments
Are you using Vuex in strict mode? If so, you might not be able to use the copy feature. I'm not certain that this would be the issue, though. By the way, there's a new API coming that will allow multiple copies, you can check out the tests here: https://github.com/feathers-plus/feathers-vuex/blob/models/test/service-module/service-module.test.js#L29 |
Thanks for the reply... and the incredible work with this package! Yep, thats right, if i disable strict mode it allows the mutations. Is that the ideal solution? Any other way around it? Cheers :) |
Nuxt ships with vuex strict mode by default, but its easy to disable in the store itself if anyone stumbles across this. |
Uggh. I personally don't use strict mode, although I can see how it would be beneficial. It basically means you have to create a mutation for every change to an object. So, to update a user's age, instead of just pulling down a user record and doing The official stance on vuex strict mode is that it requires much more work to implement it, period. The new API will open it up to allow better support for strict mode in a future release. The goal of The simplest way for somebody to support strict mode right now would be to create their own deep-cloned copy of a record as it comes out of the store, make changes to it, then use the |
I'm really glad you opened this issue because it got me thinking more about strict mode. I thought that adhering to So here's a preview of what's coming: Suppose you had an API that returns {
id: 'todo-1',
description: 'todo description',
itemId: 'item-2',
item: {
id: 'item-2',
test: true
}
} I've got it currently setup so that when this todo is inserted in the store, Here's a mostly-full example: // Setting up the store
this.store = new Vuex.Store({
strict: true,
plugins: [
service('todos', {
instanceDefaults: {
id: null,
description: '',
isComplete: false,
itemId: '',
item: 'Item' // This sets up the relationship
}
}),
service('items', {
instanceDefaults: {
test: false
},
mutations: {
// Here's our custom mutation for updating the `test` boolean
toggleTestBoolean (state, item) {
item.test = !item.test
}
}
})
]
})
// Now, assume the below code is in a component
const { Todo, Item } = this.$FeathersVuex
// When you create instances that already have an `id`, they get added to the store, automatically
const todo = new Todo({
id: 'todo-1',
description: 'todo description',
itemId: 'item-2',
// Because we setup the relationship, this gets added to the `items` store, since it also has an `id`
item: {
id: 'item-2',
test: true
}
})
const storedTodo = store.state.todos.keyedById['todo-1']
const storedItem = store.state.items.keyedById['item-2']
// Calling the mutation to change a record's property works fine in strict mode
store.commit('items/toggleTestBoolean', storedItem)
// Changing the property directly will throw errors in strict mode
todo.item.test = false
assert.equal(todo.item.test, false, 'the nested todo.item.test should be false')
assert.equal(storedTodo.item.test, false, 'the stored todo.item.test should be false')
assert.equal(storedItem.test, false, 'the stored item.test should be false') So, if everything works out, this will all work in |
The pre-release works really well with strict mode, by default. I'm closing this issue because the pre-release is stable. |
My issue was that some parent scope data was being changed outside the async block. The solution is to define anything you modify in the same block. Bad when you have more than 1 page:
Good always:
In this example |
Hi,
I have a vue component, essentially like the below, allowing user to edit
myCopy
withv-model
fields, then commit or reject the changes.This works great until i start to edit one of the input fields, and I get this error:
I can prevent the issue, by changing my
store.js
file like this solution:nuxt/nuxt#1917 (comment)
I don't feel like that is the right answer, and was just wondering if the
getCopy
getter should support a Two-way Computed Property like so:https://vuex.vuejs.org/en/forms.html
Many thanks
The text was updated successfully, but these errors were encountered: