I'm using Silverlight 3 with RIA Services without DomainDataSource.
When binding to a PagedCollectionView (or ObservableCollection) in a MVVM the Dirty State on the Dataform doesn't come up (the asteriks). When I change an assocation chosen via a childview the Dirty flag comes up after changing an assocation twice. (I change the assocation in code.)
I suspected the Dirty flag comes up with the implementation of INotifyPropertyChanged, which ofcourse all entities are implementing correct, but clearly it isn't.
When does the Dirty flag comes up?
Thank you for your answer. I worked around the problem I had.
But you are right about the IEditableObject. When the dataforms commits, the entity is Dirty and the asteriks is visible.
Related
I started playing around with Android JetPack (ViewModel, Architecture Components, LIfeCycle and so on).
Untill now, I was working with Model View Presenter architecture, and actually I found it a quite easy to test and maintain architecture.
On the other hand, The big advantage I can see by using ViewModels instead, is their native coupling with Activities and Fragments lifecycle, which always was one of the biggest pains for Android developer, so I think this is a very big step forward.
Said that, I think there is a big disavantage though: with this new approach, it seems much more tricky to call Activity's or Fragment's methods, because, as stated in the official docs
A ViewModel must never reference a view, Lifecycle, or any class that
may hold a reference to the activity context.
In MVP approach, the Presenter had a contract with the view and could call all of its methods. I made some research on how to address this scenario with Architecture components, but it seem there is no easy and painless way to do that: at the end you always have to handle states in ViewModel and react to these changes in Activities and Fragments. Someone suggest to use SingleLiveEvent class, which makes it a little bit easier, but still much more painfull than before.
So my question is:
The docs say you cannot reference anything holding a reference to an Activity Context (to avoid memory leaks I guess), but what if I do that and then I clear all references in ViewModel's onCleared()?
You wouldn't avoid memory leaks, because for example if you rotate your device your activity will be destroyed, then recreated, but the VM would remain the same, and it's onCleared would not be called (hence your old activity still remains in memory, since your VM still references it).
Generally the MVVM conceptually says, that the ViewModels should not know about the View and this is the beauty of architecture: there is not a better pattern, just a more suitable one, and you should choose the one, that works better for you.
I can think of couple of ways to "notify a user" of the ViewModel:
A LiveData object that changes and an Observer to this data
Send a Broadcast to a BroadcastReceiver using the Application's Context, if you don't mind accessing it statically from the ViewModel
Edit: I know this is not exactly an answer to the question, but I think it removed the need for it
but what if I do that and then I clear all references in ViewModel's onCleared()?
That is far too late. onCleared() is only called if the Activity is finished / the Fragment is removed, it is not called on configuration changes.
But you could potentially use some form of command queue to emit events only when a subscriber is available, for example DispatchWorkSubject in RxJava2-Extensions.
Just make sure you make your subscriptions in onStart and then dispose your disposable in onStop.
I am looking for someway how to preserve methods which I add to my classes which are generated from Core Data. It should be mainly init methods but It could be other methods too. When I was looking best approach for this I found this question but It's a little old and I hope there is better solution now. So exists better solution?
I think creating Categories like suggested in the accepted answer on the question you're referring to is a valid approach. The other option is to stop generating the files when you've reached a stable point for your entities. Normally they shouldn't keep changing too much (since that will introduce challenges with migrations etc). And if the changes are small enough (like adding a new property etc) its easy to do this manually.
You could also have a look at Moogenerator which I know a lot of ppl who are happy with.
I've got a little app using Core Data via MagicalRecord that is working fine, in its rudimentary fashion, thanks largely to the help I've found here.
Now, I've discovered that I need to add a new attribute on an entity in my data model. And, belatedly, I've also discovered that I should have used the MagicalRecord method "setupCoreDataStackWithAutoMigratingSqliteStoreNamed" instead of the plain Jane "setupCoreDataStackWithStoreNamed:"
I understand that the automigrating option will take care of the lightweight migration (my first) automatically.
Before I get myself into real trouble, can I simply change that one line of code in the AppDelegate from:
[MagicalRecord setupCoreDataStackWithStoreNamed:#"MyDatabase.sqlite"];
to:
[MagicalRecord setupCoreDataStackWithAutoMigratingSqliteStoreNamed:#"MyDatabase.sqlite"];
Be gentle with me--in all the tuts and research I've done, the issue was never addressed up front, I mean, making sure all possible attributes have been thought of and included when creating the data model and before deciding on which MR option to use. I'm sure this gotcha would have been obvious to a more experienced programmer, but it wasn't to me. :)
Thanks!
Yes, that should be just fine. All the auto migrating method does is set some configuration options to the stack setup. The rest of the initialization is identical to the basic setup.
However, if you're using your app in development, I would also recommend just deleting the old version of the store and starting over. This is commonly how I work in development when I am rapidly updating or modifying the core data model for an app.
I am working on MVC3. not sure whether its the right question but it keeps on bothering me always.
I have a generic model used by multiple views. If i make any changes to the model variables for example name change it does not reflect in any of the views nor does it throw any compile time errors. The errors are thrown only at run time.
This can cause a serious issue if model changes are not checked for in each view manually.
Is there any way to overcome this manual changes in the view?
There are two things that can help. The first is T4MVC, although this is really more about making your helpers more compile-time safe. This won't, by itself help. If you also follow these instructions then it will also compile your views and catch most of these errors.
Be aware, however, compiling views can significantly slow the build process.
nope... that is something you must be aware of, when "fixing" your model.
as the model gets evaluated at runtime, just like ViewBag and ViewData, you will have to update changes manually.
i guess you could update the changes with a nice "Search and Replace" though
I came across this a few times in my career and never really found an answer. My question is in regards to a web form that contains multiple controls that the user can update, and then saves the data to a database (easiest example I can think of right now is a user profile form - see SO profile edit screen).
So far, I have always just saved every control's value to the database. To me, it seems easier to have one method that calls one stored procedure, passing all the page's form values in.
I have seen pages that seem to save the individual control's value, rather than the entire set of controls. It can definitely look nice (if the page is doing it through AJAX), but is it better? I would think you would need more overhead to get this done, like one (or many?) DTO, more methods, and more stored procedures?
Which way is better? And are there any examples of how the individual control way is done?
Thanks!
I'd generally recommend using the individual control method; it provides for much greater granularity of design.
Depends what you mean by better.
"one method, stored procedure" - quicker to code, easier to maintain. "save the individual control's value" - more optimized? I'd leave optimization to last. Looks nicer? Is usability actually a problem on this page? YAGNI - fix performance/usability only if they are broken.
Some thoughts
It's one call to the database whether it's 25 columns or a single column
(Similar) If you update 6 controls in one edit session, you do it in one call rather than 6 separate ones
You may have forms with dependent or linked controls or disallowed value combinations: The general case would be "multiple control" changes in one edit session: so code for this
The general idea of auditing/timestamping is at the unique *row *level, not column.