According to Firebase docs:
ChildAdded is triggered once for each existing child and then again every time a new child is added to the specified path
So, I have an app, that has a little banner at the top that pops up every time a user gets a new message. As you could have guessed, these messages are stored in a child in the user object in Firebase. So, here's the problem, when I load the app, it pops up for EVERY message the user has. Is it possible to have this observe event ONLY be called when a new child is added? I don't want it to be triggered for every single existing child, only when a new one is added. I would hate to have to store message references in core data, and do a check for every child to see if it already exists in core data :/
A few ways to do this:
Use ref.queryLimitedToLast(1) when you start. See Firebase, only get new children.
keep track of the most recent key you've got in your local storage and then query with queryOrderByKey().queryStartingAtValue(latestKey)
Add a timestamp to the items and then queryOrderByChild("timestamp").queryStartingAt(now) for items with timestamp >= now. See how to discard initial data in a Firebase DB
Related
I am using NSPersistentCloudKitContainer, not sure if that's the cause of my issue or CloudKit generic behaviour. The sync setup works fine so far. I am now adding a new feature, causing some an issue:
I have an entity Item, which can be put in a Group. Relation in CD is to-one and optional. Works fine on device: I can set and remove group, everything is persisted.
But CloudKit just ignores when I remove the group. It does not complain, just ignores it. No matter if remove happens from Item, Groups or both sides. On next download it’s back in a group. Is it just a bug in NSPersistentCloudKitContainer? It’s possible to nil fields on CloudKit records, right?
What I see in CloudKit dashboard:
• Group field on Item is of type String.
• A fresh Item record, never assigned to a group, does not have the group field.
• As soon as it gets a group field, I can’t get rid of it. Emptying the value causes to crash.
When I get the CloudKit record on device, it does not even have the group field. So I can't manually reset it. It only shows the Group field in the CloudKit dashboard. I guess the container handles the relationship internally and only maps it during sync.
Is there any way to properly handle this?
I am using provider to build my application, so the data is added to StreamController, and each time i refresh my app, it will call an API, and then push data to StreamController, and the question is how to remove the data before replacing with the new one?
controller.add(user);
To iterate the answer from the comment. There is no need to remove any data added to the StreamController instead, just adding a new data again will remove the old data from there. You can do something like this:
controller.add(newOne);
You can also check this reference to understand the concept of Stream with examples.
I have created a fusion web app in adf 12c and using 12c database.
After building my application, I accidentally delete some rows in table but didn't press commit button. The deleted rows are not showing there but present in database(checked after refresh). I want to refresh data from database either on page refresh/reload or through some command button. How can i do that without rebuilding my application.
Here is how to implement a rollback on an ADF table?
Go to your Datacontrols panel
Open the application module where the View Object of your binded RichTable originate
Go to the Operation folder
Drag and drop the rollback operation as an ADF command button to your JSF page
it will look like this :
<af:commandButton actionListener="#{bindings.Rollback.execute}" text="Rollback" disabled="#{!bindings.Rollback.enabled}" immediate="true" id="cb6">
You can also do it in Java :
appModule.getTransaction.rollback();
This rollback operation will cancel all the modification done to the application module and query the database again for all his View Object.
Read more here : https://docs.oracle.com/cd/B14099_19/web.1012/b14022/oracle/jbo/ApplicationModule.html
Transaction
Associated with the root Application Module is the Transaction object,
which provides this transaction context. From any (root or nested)
Application Module, the user can retrieve the transaction object
through a call to getTransaction(). In reality, getTransaction() first
locates the root Application Module and then returns the transaction
object from it.
The Transaction object manages connection to database and Entity
caches. Thus, changes made through one View Object are visible to
other View Objects as long as these View Objects all parented by the
one root Application Module. In contrast, if two View Objects are
parented by two separate root Application Modules, then changes made
through the View Object will not be seen by the second View Object
until the changes are committed to database through the first root
Application Module and the second VO executes query (to retrieve the
most up-to-date data from database).
You need to pick up the executeQuery operation for the View Object that populates your table and drop it on your page as a button. Pressing the button will re-query your DB to fetch the data from there.
I have a project and I am using core data.
I have some entities, with attributes. When I started the project I choose some atributes and now I want to change their types (Int to String for example). ANd so I did it.
THe thing is, I am getting errors...
I checked the code, I think every thing is ok.
I even deleted the entire entity and made a new one with some name but it doesn't work.
How can I change it with success?
You can use code data migration for this by creating new version..
To change data types you need to create a new version of the database, you can not just simply modifie it because that way your users would have to delete and redownload your app every time you change something.
Here you can read how to do this.
The simulator or device you are running the app on still 'remembers' the old type and data. Simply hold down on the app and press the 'X' to delete it. When you press play in XCode it will reinstall the app with the new data types.
In our app we need to check if the data is saved when we are in a particular place before navigating away from it. So the user should be able to negate a browser back button request. But by the time that the history value change event is received the url has already been changed. The History class doesn't seem to have a way to restore the url back. Anybody have any ideas?
In GWT 2.1 you get Activities and Places. And activity has a maystop method, which is exactly what you want, if I understand you correctly.
Use a window.onunload or window.onbeforeunload javascript callback to confrim/save state.
onbeforeunload example
I haven't actually implemented this behavior yet, but here is my plan and maybe it will work for you.
1) Each time you receive an onHistoryChanged event and decide to allow it, save the current historyToken in an instance variable somewhere.
2) Keep track of activity on the page that should block navigation. Use a data structure that can keep track of multiple activities, like multiple file uploads, multiple edits, etc.
3) When you receive a new onHistoryChanged event, if your data structure from #2 indicates that it's not safe to navigate, avoid changing the page and restore the historyToken that you saved in #1. I'm assuming that you can do this either by:
a) Calling History.newItem(oldHistoryToken, false) or
b) Calling History.newItem(oldHistoryToken, true) and keeping a flag to force the next onHistoryChanged to be ignored.
Again, I haven't actually implemented this so let me know how it works out.
If you have links that allow the user to leave the app and you want to prevent that as well, you'll need to also add an onbeforeunload.
Have a look at the PlaceManagerImpl class from the gwt-platform framework. Especially the onValueChange() method and the methods dealing with the onLeaveQuestion field.
Hope that helps.
In this issue report, t.broyer explains in his comment that such behavior was planned during design of Places framework. The most important part is:
mayStop was a mistake, or it should have only been called when unloading the app, not for internal navigation within the app.
So probably it's better to not use it at all...