I have a question regarding RTK Query migrations.
To be clear: I am not wanting to migrate from one library to RTK Query, but I want to add a field or Tag to my query. The query results are saved in the store, but sometimes when you want to add a new field which is not in the old store, the new code can crash.
I have problems when adding a new field of adding a new Tag. I solved it by resetting the whole store, but this is off course not nice in production.
In the "old" way (when I only used RTK, not RTK Query) I used to use createMigrate().
Thx in advance!
my old code I wrote a migration like this:
const persistConfig = {
key: "root",
storage,
version: 8,
migrate: createMigrate(migrations, { debug: MIGRATION_DEBUG }),
};
Related
After going through a number of answers on here I still wasnt able to quite figure my issue.
I am working on my first webapp with vue.js and firebase. I was able to to get everything set up to the point of creating new records and sending the name field to the db. I then added another input option with vue select where users can pick a options from a drop down field. When I try to add this second input to the $emit and have it as a property on the created db record, it just keeps duplicating the "assessmentName". I believe this is because I need to do something specific to $emit multiple values, but I just can't seem to figure that out.
https://github.com/mfarry87/AppTrial/blob/master/src/views/Assessments.vue
https://github.com/mfarry87/AppTrial/blob/master/src/App.vue
To update a Firestore document you'd need to call the set() method with the { merge: true } options object passed in as the SetOptions argument.
addAssessment: function(payload) {
db.collection("users")
.doc(this.user.uid)
.collection("assessments")
.set({
name: payload,
criteria: payload,
createAt: firebase.firestore.FieldValue.serverTimestamp()
}, { merge: true });
},
That will also create the document if it does not yet exist.
I'm new to all of these technologies, but as far as I understand it, you can use React Native with Redux and Firebase without react-redux-firebase. You could just use
react
react-native
redux
react-redux
react-native-firebase
Then you load data from Firebase (e.g. Firestore) and put the data in a reducer so it gets merged into the redux store.
Why do I need react-redux-firebase? What problem does it solve?
I have tried its docs, but they seem to be written for someone who is already familiar with its goals. They do not really explain, and when reading the examples, I do not understand why I specifically need react-redux-firebase instead of the setup listed above.
Firebase is on your state, listen to it an modify it, it will change your Firebase database. After the data on the database is changed the components listening will change as well.
This will create an item in the database
updateTodo: props => () => {
return firebase.update(`todos/${params.todoId}`, { done: !todo.isDone })
}
So any component listening to that node will get updated:
connect((state) => ({
todos: state.firebase.data.todos,
// profile: state.firebase.profile // load profile
}))
It solves the problem of having multiple sources of truth, your Firebase database is your only source of truth, otherwise, you change your local data and then you update the data online and then if it works nothing else but if it fails you have to update the local data again
I run a chat application with Firebase Firestore and it works all super well, however I'm running into the following issue:
For paginating my conversations & chats I use query cursors for my listeners. I save these query cursors into my state (vuex) so I can access them later when needed. That works and I can paginate my chat messages and conversations.
I create query cursors like so:
const query = await ref.get()
const cursor = query.docs[query.docs.length - 1]
commit('SET_CONVERSATIONS_QUERY_CURSOR', cursor)
And later use them in the next query like so:
.startAfter(state.conversations.queryCursor)
Everything actually works perfect.
My issue now is that that cursor saved in my state seem to be updated regularly (...why Firebase?) & especially directly. This gives me the following error messages when using vuex strict-mode (-> not allowed to access the state directly):
app.js:506 Error: [vuex] Do not mutate vuex store state outside
mutation handlers.
Now I of course want to use strict mode to avoid mutation state directly, but I can't due to the query cursors in my state.
I tried to clone the cursor before saving in to the store, but shallow clones did no good and deep clones did not work because of Converting circular structure to JSON.
So...
Is there a recommended way on how to store query cursors for later use?
Are there options to just store the id of a document and later "recreate" a query cursor?
Thanks!
You can prevent javascript object from getting modified by using Object.freeze(obj).
So in your case it should be const cursor = Object.freeze(query.docs[query.docs.length - 1])
Recently started using rxJava in one of my projects. There are several demoes out there showcasing the use of retrofit and its observables for display but can somebody show an example of doing this with our own database.
I tried it myself ref: this question
But am unable to think of a way to properly combine all the generated object observables into a list that can be updated inside the adapter in one go. toList seems to terminate the observable after the first run, thus can't be used directly.
Thanks!
To observe changes to a SQLite database using RxJava you can use SQLBrite.
To query the table users you can use:
Observable<Query> users = db.createQuery("users", "SELECT * FROM users");
users.subscribe(new Action1<Query>() {
#Override public void call(Query query) {
Cursor cursor = query.run();
// TODO parse data...
}
});
You will also receive notifications for updates/inserts as long as you are subscribed.
The code sample is from the documentation on github.
I'm building an online store in meteor where customers can customize products in the store. I have setup a client-only collection called Inventory which stores all the product data and is updated accordingly in response to user input. Once the user is ready to checkout, I dump the product data into a client & server side collection called ShoppingCart. I want to allow users to go back and revise their edits on the product in Inventory so I setup my router to $set data from the ShoppingCart into Inventory if it finds a match:
Router.route '/:_type/:_id', ->
Session.set "inCart", false
#render #params._type,
data: =>
storedItem = ShoppingCart.findOne {
userId: Meteor.userId(),
image: #params._id
}
if storedItem?
delete storedItem._id
Inventory.update {image: #params._id}, {
$set: storedItem
}
Inventory.findOne image: #params._id
EDIT: This seems to cause my router method to get stuck in an infinite loop whenever data in Inventory changes. Is there any way to avoid this issue? Is there a better way of handling this kind of data altogether that I should consider?
MAJOR CAVEAT - I don't do CoffeeScript, so this is what I can gather having put your code through a compiler.
I think the problem is that the data function is reactive, and you're updating and returning an item from the Inventory collection within it. Every time the route runs, unless there is no storedItem, it's going to invalidate a computation on which it itself depends and thus rerun again immediately (and subsequently do the same again, etc...).
As a general rule, I think it's a very bad idea indeed to be updating a collection from within a data function - if you have to do this within the route function, consider the onRun, or onBeforeAction hooks for the update.
Final thing, just because I don't understand: why do you need to dump the item from the ShoppingCart back into Inventory? Shouldn't it already be there, unless the user has started a new session?