Sencha Touch associated model fetching - sencha-touch

I have a model "Order" that "hasMany" "Item"s
I get a push notification from my server that a new Item has been added to the Order. I also get the new Item's id. Now, I'd like to fetch that Item (from the server) and then add it to the Order.items() store locally i.e. I don't want sync to happen on the store – the store after the add should assume that it has the fresh data and should not feel the need to contact the server to "sync" anything.
Any thoughts on how I should approach this? Thanks!

Related

Saving data into session or localstorage

So probably every e-commerce site has a feature like if you add products to your cart it will be existed everywhere weather its in your phone or computer or tab.I know how to store data in session but when I jump into another device I can't see my cart products available though I use the same account.So please can anyone tell me how to store data in session or local storage that won't be removed by jumping device and will be changed when the user's state changes.I am trying to do that by using vuejs.I will be very glad if you give a solution based on vuejs.Thanks..

firestore how to check if new documents added matching a particular query

As I know that, instead of get() I can use onSapshot() for my queries and listen to the changes(additions, deletions, modifications) for that query. But when there are changes, onSnaphot() returns multiple full documents whether modified, deleted or added (a new snapshot). What I want to do is, to check if new documents have been added matching my query and show a notification to the user that there are new records available, and only when a button is clicked, they should be able to fetch and see the new records. I don't want to fetch from the firestore whole sets of documents when there are changes. I just want to know about those changes and fetch on demand. And fetch only the added ones.
How can I do that? Any ideas?
By the way, I am using react-native for my app.
P.S. - I know, I can run the query periodically and check if the id of the first item in the new query matches the first item id in the previous query, and so I can detect the added records and show my notification/button. But I am looking for a more elegant solution. I think the notification should be triggered from the backend instead of polling the backend periodically.
P.S. 2 - Using cloud functions would not seem to be a logical option since these queries will be different for each user of my app. Which would require running thousands of functions (hopefully more) on the firestore. Or would it?
Thanks!
There is no way in the Firestore API to get notified about changes to a query without actually retrieving the changed documents. But you can of course show just a notification to the user when your onSnapshot callback gets called, and then only show the actual data from those documents when the user chooses to refresh the UI.
On a second note, when you use a snapshot listener the Firestore client will only retrieve the modified documents on additional callbacks.
Say you attach a listener for a query that matches 10 documents. On the first onSnapshot callback, you will get 10 documents and will be charged for 10 document reads. Now say that one of the documents changes. When your onSnapshot callback gets invoked for this, you will see 10 documents again, but will be charged only 1 read - for the document that was changed.
If you only want to process the changes, have a look at the documentation on viewing changes between snapshots, which contains a good example of how to do this with the docChanges() method.

Delete/Discard previously saved data from HealthKit

I'm developing an app that gives the users the option to track what they ate. One of the features the app suggest is to select a food item as Eaten. When a user does that, I share that info with the HealthKit.
A user can then decide to uncheck that item and return its previous state: Uneaten. I wonder if I can query the previously saved food item and choose to delete it from the HealthKit as it isn't relevant for the user anymore?
UPDATE
Well, After reading almost the entire documentation of HealthKit I found out that HKHealthStore object has a method: deleteObject:withCompletion:. Yet I can't seem to successfully delete an HKCorrelation that stores the food item I previously saved to HealthKit, though the call finish successfully (I can still see the data in the Health App)...
Use the deleteObject:withCompletion: API to delete the objects you saved. If you saved an HKCorrelation you must delete each of the objects you saved with the correlation as well.

Spine.js model - resource creation before id is updated

Guys,
I have two models, Notebook and Note. Note belongs to a notebook and notebook has many notes.
In my application I have a very common 3-columns view, 1st col lists notebooks, and 2nd col lists the notes corresponding to the selected notebook, and the 3rd col contains a form of the currently selected note.
In Spine, I didn't use the relation module. Every time the user selects a notebook, I call get /notebooks/:id/notes to fetch the corresponding notes of the selected notebook and render the note list, and when user click to create a new note, I will create a Spine object of note model with the current selected notebook_id and call save(). It works fine with the existing notebooks.
But there's a problem when a user creates a new notebook. If user click to create a new note inside this new notebook, before the notebook create ajax finishes, I don't have the actually notebook id from the database. So I think I have to wait for the notebook create ajax call back, before then I will block the user from clicking to create a new note.
But from Spine documentation, Alex said: Waiting for a server response goes against the whole concept of an asynchronous user interface.
So, what's the correct way to do this? Am I doing it right?
Thanks a lot.
In some cases it is way more complicated to not wait for a server response. It is up to you to decide when the non-blocking UI is worth the extra development effort and code complexity. In this case it shouldn't be terribly hard to trigger updating the reference ids on notes when the id on the notebook is updated, however it sounds like you wouldn't want to allow attempts to persist the note before that happens. That is doable without a blocking UI though.

How can I set up a newly created relationship in Core Data on iOS?

So I'm using Core Data in an existing iPhone app, and I've set up two entities: Person and Item. The root view of my app's navigation (currently) shows a list of people, and you drill down from there to items. In short, the hierarchy looks like this:
Person -> Item
I want to add a new entity above Person in the hierarchy, called List:
List -> Person -> Item
Additionally, I want the user's first List to be created for them on startup, and for any People the user's already added to be assigned to that list.
I'm familiar with Core Data's lightweight migration & versioning feature, so I think I know how to add the new entity and relationship, but I'm not sure how to:
Create a List record on app start if they've never had the Lists feature before
Set all existing People records to belong to that new list.
One quick and dirty way would be to add some code to my app delegate's applicationDidFinishLaunching method that performs the migration by (1) checking to see if there are any Lists, (2) if not, creating the default one, (3) fetching all existing People from my data store, (4) setting each Person's list attribute to the newly created default list, and finally (5) saving those changes.
My question is: is there any faster or easier way to do all of that?
That's pretty much what you'd want to do. Use an NSFetchRequest to see if any Listss exist. If not, create one. Then do another request to get all the Persons. Here, instead of assigning the list property of each Person, I'd create an NSSet containing all your Persons and assign that to the List's people property. You did create an inverse property, right?
This is actually a pretty lightweight operation, all tolled, so I wouldn't worry too much about performance. Unless you've got hundreds or thousands of Person objects, your user will probably won't even notice.