In QAbstractItemModel, whenever the data changes, a signal is emitted that we can listen to. E.g. when a particular field changes, the QTreeView or what have you re-draws to reflect this.
With web-applications, this doesn’t seem to be the case. Using MongoDB for instance, interacting with the model (database) typically (seems to) include an additional interaction with an event (however I’m very new to it).
# Example
def update_field(content):
field.setText(content) # Update visually
database.insert({"key": value}, content) # Update model
Firebase on the other hand looks more like QAbstractItemModel, in that for each change there is an event.
https://www.firebase.com/docs/web/api/query/on.html
firebaseRef.on('value', function(dataSnapshot) {
// Model was updated
field.setText(dataSnapShot.val())
});
It may be due to familiarity, but it seems more intuitive to me to listen for changes on a model, than to double-up on updating both views and models from a controller when it comes to changes to data.
Are there other databases that does this, that isn’t cloud-based? Is this a common practice? Why not?
Best,
Marcus
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOALCSxNB%2B3ZbLLLrk7_%3DjQY2nRQDiqt%3DL7X%3Dz9XBLYZAg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
This layer allows you to emit your signals to connected clients.
Yeah, it was this I was trying to illustrate with the above update_field() function; that a user-event is sent to both the view, rendering the field, and the database, persisting the change; whereas in Firebase and QModel, views can instead be connected directly to the data-source (switching the name from “model” here as you said database and model aren’t necessarily exchangeable).
It comes down to the decision of whether you want to host your own services, or run them in the cloud
Do you know of a local equivalent of this? The concept of Firebase seems applicable outside of cloud-hosting, but maybe there’s something I’m missing.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA1VSk3jjOpSk%2BC7wrgjFFHO_6b-0-ueuxgDS3wjtsFDJw%40mail.gmail.com.
They act as an application server that allows for all of the notifications when your data flows through their layer in and our of the underlying MongoDB.
Ah, I see. So they are essentially doing this extra step for you, of both persisting and emitting a signal. I suppose this could be done quite simply via an abstraction/wrapper of any database with which you handle all communication to your database.
Ya it is exactly what you would do in your own local application server layer. Theirs is just a packaged and priced service.
For the model thing though... Even the qt models don't necessarily react immediately to changes in the sql server. The model has to be told to refresh it's query or designed to know how to monitor it's data source. The result is that as soon as data changes in the model, the views will know. You can write a Qt model around a mongodb backend to provide views with instant updated but the update comes from when the model is told to query Mongo again.
Maybe that was the same point you were making. By those same standards, you could design a Qt model that abstracts a datastore that does provide notifications and have it refresh in a push fashion. But again that is all transparent to the view. Just depends on what your model is modeling.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOD%2BwxhGTqve%2ByjrsF-y08H3L0Y-ATjFE2RhYgs9fALuqQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA369rb3J3CHgT0J43xsaure8aJ7VgoQeFKoFNqEkdQDNA%40mail.gmail.com.
A web app is just one example. Any kind of app server may or may not provide a push notification to its connected clients, and may or may not be using a database that supports push notifications.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmODUDu54DtV2xrQUn9FxBiP4ZhhOSyLcoa6p24cMcCkKhQ%40mail.gmail.com.