is there any way to observe any change to [NSUserDefaultsController sharedUserDefaultsController]?
I know I can observe a single value but I'd rather consolidate all these individual observers into one.
You can observe the NSUserDefaultsDidChangeNotification notification.
Related
I often use combineLatest to combine 3 or 4 Observables to calculate a simple condition.
If one of the 'combined' Observables doesn't emit then this will block until it does. It can be very tricky to debug if later down the line something that has always emitted immediately stops emitting.
Side-note: I'm specifically needing this for UI related logic, where there may be observables that represent things like screen width / scroll position / etc. So they're supposed to always be there - but if it breaks suddenly (especially on mobile) it's difficult to track down what's blocking it.
So what I need is something like combineLatestImmediate that errors if all inputs aren't immediately available. When I say 'available right away' it's typically something that comes from a centralized data store, or a behaviorsubject (which of course will always have a value). But when it breaks...ugh.
Is there a better way than:
combineLatest(obs1, obs2, obs3)
.pipe(timeoutWith(0, throwError('Expected obs all to be available')))
or even:
// note: take(1) is required or the wrong observable
// may get reported if the source hasn’t closed
combineLatest(obs1.pipe(take(1), timeoutWith(0, throwError('obs1 has no value'))),
obs2.pipe(take(1), timeoutWith(0, throwError('obs2 has no value'))),
obs3.pipe(take(1), timeoutWith(0, throwError('obs3 has no value'))));
You could put a non zero value for timeout if you wanted a grace period, or make this into a custom operator. But I'm finding a need more and more for this.
It's a safety / sanity thing, to save time debugging.
Also I'm not looking for forkJoin (which short-circuits if any of the inputs are EMPTY). I'm talking about when a value is just not immediately available - usually .
I have used C# to add elements to my layout that has a name of detailsLayout. I add about 20 grids elements and inside each of those are more elements:
Now I want to delete those elements. Is there a difference between these two ways:
detailsLayout.Children.Remove();
and
detailsLayout.Children.Clear();
I didn't verify this but I could imagine the following. Remove is intended for removing 1 entry. By doing so, the remove will also call all kinds of events associated with the removal of one entry. Such as maybe updating the UI or triggering an event.
With Clear, all children are first removed and then all associated actions, like, again updating the UI or triggering an event, are done. Because it is apparent that you want to remove all the children since you are calling Clear the system can wait to trigger resulting actions until the operation is done.
In this case, it will mostly be a matter of performance. In the end, both will have the same result.
I have a class that implements a file-monitoring service to detect when a file I am interested in has been changed by something other than my application. I use the standard technique of opening the file (with the O_EVTONLY flag) and binding the file descriptor to a Grand Central Dispatch source of type DISPATCH_SOURCE_TYPE_VNODE. When I get an event, I notify my main thread with NSNotificationCenter's postNotificationName:object:userInfo: which calls an observer in my app delegate. So far so good. It works great. But, in general, if the triggering event is an attributes change (i.e. the DISPATCH_VNODE_ATTRIB flag is set on return from dispatch_source_get_data()) then I usually get two closely-spaced events. The behaviour is easily exhibited if I touch(1) the object I am monitoring. I hypothesise this is due to the file's mtime and atime being set non-atomically although I can't verify this. This can lead to spurious notifications being sent to my observer and this raises the possibility of race conditions etc.
What is the best way of dealing with this? I thought of storing a timestamp for the last event received and only sending a notification if the current event is later than this timestamp by some amount (a few tens of milliseconds?) Does this sound like a reasonable solution?
You can't ever escape the "race condition" in this situation, because the notification of your GCD event source in your process is not synchronous with the other process's modification of the underlying file. So, no matter what, you must always be tolerant of the possibility that the change you're being notified for could already be "gone."
As for coalescing, do whatever makes sense for your app. There are two obvious strategies. You can act immediately on a received event, and then drop subsequent events received in some time window on the floor, or you can delay every event for some time period during which you will drop other events for the same file on the floor. It really just depends on what's more important, acting quickly, or having a higher likelihood of a quiescent state (knowing that you can never be sure things are quiescent.)
The only thing I would add is to suggest that you do all your coalescence before dispatching anything to the main thread. The main thread has things like tracking loops, etc that will make it harder to get time-based coalescing right in certain cases.
Could you please tell me why sales_order_save_commit_after is triggered twice when order is completed?
I moved all logic to sales_order_save_before, but I use sales_order_save_commit_after to make sure that it's called only once. I want to make sure that there are no superflous writing to database. I tried to use debugger to understand how it works, but I haven't understood so far, it seems rather complicated.
I see 2 callbacks but I can't understand why is there 2 callbacks for model order.
Does magento write to database several times that triggers sales_order_save_commit_after multiple times?
If an order contains configurable products, the collection returned by $order->getAllItems(); will contain parent and child products resulting in double element count for this product type. It is safer to use $order->getAllVisibleItems()
Suppose that I have a view-state targeted by many states. So many of them will have transitions with destination this state. For some of them, I want to display certain data on the page. So suppose if from state A->B then don't display, if C->B display.
I thought that if I knew the event that triggered the transition, I could easily do this... but I can't find a way (I am new to SWF).
Do you know how to do that? Or alternative ways to get the same result?
I've done something similar to this using a FlowExecutionListener. FlowExecutionListenerAdapter is provided as a base class for adding behavior on transition, state change, etc. An example of how to register such a listener can be found here in the docs. Each method is passed a Definition that contains meta data about the event. From that meta data you can determine if the event is one you're interested in and execute your custom logic.
Hope that helps.