We have an NSTextView and some data saved about its contents in a core data Managed object context. Everything works great while the managed object context stays in memory. However when we save it, we get very weird fetch request behaviors.
For example, we run a fetch request that asks for all elements with a textLocation less than or equal to 15. The first object in the array we get back has a textLocation of 16.
I know I can't get a definitive answer here, as the code is fairly complex. But does anyone know what this issue smells of?
My thought is that we are somehow not getting the proper MOC synced with the NSTextView after saving? What could change that breaks this?
Thanks.
For example, we run a fetch request
that asks for all elements with a
textLocation less than or equal to 15.
The first object in the array we get
back has a textLocation of 16.
Really, the only way to get that is to (in reverse order of likelihood):
Mess up ethe definition of the attribute such that you think your are saving one type of numerical info but that you are actually saving another.
You've mangled the predicate so that it actually looks for values of 16 or greater. (You can test predicates against an array of dictionaries whose keys have the same names as you Core Data entities.)
It's an error in the conversion between a number and a string for purposes of displaying in the UI or logging.
I would start with (3) myself because it seems more common and until you confirm you don't have a display problem, you can't diagnose the other problems.
I finally managed to work out what was going on. I was setting textLocation using the setPrimitiveValue... just because I didn't want notifications to fire off. Turns out that's a really bad idea, because Core Data didn't know the value had changed. It still thought the value was 15 instead of 16.
Let this be a lesson: never bypass KVO unless you're INSIDE the managed object and you know what you're doing!
Related
I have a web app, which allows users to edit several configurations. I want to make the users aware that they have made changed locally but not committed since their last load. When users change the configuration back, the "modified flag" should disappear.
What's a good approach to achieve it? Currently, I am thinking about keeping an original copy of the configurations, and compare current configuration with the original one each time the user made some changes, but I am worried about the performance since the configuration data is fairly large. (The app client runs in browsers.)
Please help, thanks.
I don't think performance will be an issue but if it were, I'd also create a "dirty field" map based on associative array or a hashmap/object with field names as keys. Of course all field names must be unique. This map will be initially empty.
When you edit any field, catch the onChange or onBlur event and compare just this field with the saved one. If they differ, put it to the dirty map like field_map['field1'] = true;. If they are equal, remove this key from the dirty map.
So, if your dirty map is not empty, you will know changes were made, and you will also know exactly what fields have changed.
I received an abandoned student LabView project I need to adapt. There is one VI which contains an array of two controls with length 30. I need to change the strings in several places within that array which is possible as long as I do not close the vi. If I close and reload the vi the previous values are there again, saving the changed values as default does not help. Cutting the connection to the type def did not help either.
There is also no databinding and I could not find any mechanism that might lock the values. It must be something obvious to experienced LabView developers, but I could not find anything on the net.
What can be the reason that the values cannot be changed permanently?
Edit:
After playing around for a long time, i found out that I have to set as default value on the array, and not on the individual positions in the array. That solved it, simple problem, several hours spent...
After playing around for a long time, i found out that I have to set as default value on the array, and not on the individual positions in the array. That solved it, simple problem, several hours spent...
So I realize that this question can be seen as somewhat vague, but it's actually quite specific.
I started to write this out, then realized that lack of specific verbiage makes it sound vague. So let me put it this way.
I've got an Order object, that has customer data on it. It also has, for the sake of this example, a single order for a car.
The Car has a Category, Product, Year, Color. For the sake of this example, my Order page has 4 drop downs, which cascade one to another. Category populates Product populates Year populates Color.
(I was going to go with Make and Model, then realized using "Model" was getting confusing, haha.)
I've got several problems:
I've got multiple layers of dropdowns. Four, not just one.
My drop down objects are not related to each other specifically - that is to say, I use an id from Cateogry to populate Products, but Category does not come with Products when it's retrieved. This is different than the Cart example that KO has on their website.
I am stuck with the above architecture. I need to change a drop down, then send a service call to get the next drop down based on the selected drop downs id. I can't alter the service layer to nest the objects together.
My Order comes with child objects to indicate Make, Model, Year, Color. However, since these are different, I've been using the knockout.mapping keyed array and a custom binding handler to look up data object. Thankfully I only have to do this once, as after the object in the top level is replaced, it's fine.
I've been trying to use knockout.mapping to map the relevant objects, especially considering the key thing.
However, I'm totally open to just making the objects in knockout.
The problem I'm having, and this thing has really turned into a disaster, is that since everything is asynchronous, it's very difficult to resolve things in the proper order, aside from nesting within nesting within nesting.
Hence my question - I'm getting to the point where it seems like ditching knockout completely is the answer here, which doesn't seem right. It feels like I'm very close but it still doesn't work properly. (Often things load in the wrong order.) Unfortunately I can't really post the code because it's huge.
The thing is, it seems like it shouldn't be this hard. It feels like I'm missing a fundamental design pattern for knockout and drop down combos. Looking at the cart example, I'm starting to suspect that multi-layer cascading drop downs are just not feasible in knockout at the moment unless the data is all loaded ahead of time.
Am I actually missing the design pattern? If so, please elucidate. If not, go ahead and say so. I guess whichever more people agree with will be accepted.
Update
I realized after the first comment I got that I did not discuss much about some of the solutions I've tried.
So, basically yes, I've tried subscribing to the change event. I should emphasize that at the beating heart of this problem lies the fact that all of our calls to load these dropdowns are network calls.
The problem that happens is that the change event fires multiple times - once when you load the drop down, and again when the value is bound to the drop down. At least, that's been my experience.
What ends up happening is that any subscription will then fire multiple times. When it does, it causes the load to happen multiple times. Aside from the fact that I don't want to fire multiple times, there are often issues where the drop downs will get loaded incorrectly. My guess is that one of the times arrived "out of order" than the others.
I've gotten similar results with my various efforts. It really does seem to be pushing me toward some hackish stuff, like nesting 5 or 6 or 7 network calls inside of each other's callbacks. And it seems like there must be a better way.
I've tried computed observables to similar effect. I've tried loading things once via the MVC viewbag, etc. Every time I try something, I'm stymied by either something loading weird, the knockout.mapping plugin behaving strangely (it apparently will not add its key/mapping functions to existing knockout observables) or just ... some other weird issue.
Again, I ask, is this something knockout is simply incapable of? Is our situation just too peculiar? Or am I missing some method or function or object that would make all of this work?
Knockout subcribe event will solve your problem.. Its not too complicate I think..
If you think its complicate add a fiddle or code block.
Is there a way, either natively supported by CListCtrl, or with some coding technique, to update a chunk of data in a virtual-list-mode CListCtrl instead of one at a time?
By default, when the list requires a data for a cell, we handle it via LVS_GETDISPINFO. If I have say 8x8 (64) cells visible and constantly updating, it's basically calling the handler to LVS_GETDISPINFO 64 times. This is fine and expected behavior, but I believe there is a small overhead in calling this function repeatedly, as opposed to just doing it in a for-loop for all the 64 cells. And this is a problem to me because my control constantly updates all the 64 cells (imagine something like a TCP packet trace).
CListCtrl supports caching of course (although useless in my situation), but again I feel there is overhead in calling the LVS_GETDISPINFO handler over and over again. A simple example would be, say to determine if my pointer to the database is valid (not null) before obtaining the data ... in essence this line of code is called 64 times, when I could have done it just 1 time, then for-loop the pointer to get the data of my 64 cells. Also, the pointer is just a simple example, there is more that I am doing (which cannot be avoided) that I won't explain since it requires code.
As time is of the essence, I can't go back to re-write my own list ctrl that is more efficient, as it takes time to duplicate the other benefits of CListCtrl that I am enjoying by inheriting it directly. The only issue now is speed. If there is a way, say something like a handler that passes in a null-terminated array of cells to update so that we can update this in bulk in just one function, that would be great.
Or maybe is it possible to know what cells are pending update in LVS_GETDISPINFO, so that, if possible, I update all the cells, and validate the entire update to stop getting LVS_GETDISPINFO?
Any ideas? Thanks in advance.
I've been using ReadDirectoryChangesW to monitor a particular portion of the file system. It rather nicely provides a partial pathname to the file or directory which changed along with a clue about the nature of the change. This may have spoiled me.
I also need to monitor a particular portion of the registry, but it looks as if RegNotifyChangeKeyValue is very coarse. It will tell me that something under the given key changed, but it doesn't seem to want to tell me what that something might have been. Bummer!
The portion of the registry in question is arbitrarily deep, so enumerating all the sub-keys and calling RegNotifyChangeKeyValue for each probably isn't a hot idea because I'll eventually end up having to overcome MAXIMUM_WAIT_OBJECTS. Plus I'd have to adjust the set of keys I'd passed to RegNotifyChangeKeyValue, which would be a fair amount of effort to do without enumerating the sub-keys every time, which would defeat a fair amount of the purpose.
Any ideas?
Unfortunately, yes. You probably have to cache all the values of interest to your code, and update this cache yourself whenever you get a change trigger, or else set up multiple watchers, one on each of the individual data items of interest. As you noted the second solution gets unwieldy very quickly.
If you can implement the required code in .Net you can get the same effect more elegantly via RegistryEvent and its subclasses.