Text change notification for an NSTextField

If you just want to detect when the value of a text field has changed, you can use the controlTextDidChange: delegate method that NSTextField inherits from NSControl. Just connect the delegate outlet of the NSTextField in the nib file to your controller class, and implement something like this: – (void)controlTextDidChange:(NSNotification *)notification { NSTextField *textField = … Read more

How to combine two live data one after the other?

You can use my helper method: val profile = MutableLiveData<ProfileData>() val user = MutableLiveData<CurrentUser>() val title = profile.combineWith(user) { profile, user -> “${profile.job} ${user.name}” } fun <T, K, R> LiveData<T>.combineWith( liveData: LiveData<K>, block: (T?, K?) -> R ): LiveData<R> { val result = MediatorLiveData<R>() result.addSource(this) { result.value = block(this.value, liveData.value) } result.addSource(liveData) { result.value = … Read more

How does AngularJS know when variables change? How does AngularJS dirty checking work?

From this link: Angular defines a concept of a so called digest cycle. This cycle can be considered as a loop, during which Angular checks if there are any changes to all the variables watched by all the $scopes. So if you have $scope.myVar defined in your controller and this variable was marked for being … Read more

Rails 3: How to identify after_commit action in observers? (create/update/destroy)

I think transaction_include_action? is what you are after. It gives a reliable indication of the specific transaction in process (verified in 3.0.8). Formally, it determines if a transaction included an action for :create, :update, or :destroy. Used in filtering callbacks. class Item < ActiveRecord::Base after_commit lambda { Rails.logger.info “transaction_include_action?(:create): #{transaction_include_action?(:create)}” Rails.logger.info “transaction_include_action?(:destroy): #{transaction_include_action?(:destroy)}” Rails.logger.info “transaction_include_action?(:update): … Read more

C#: events or an observer interface? Pros/cons?

Consider an event to be a callback interface where the interface has only one method. Only hook events you need With events, you only need to implement handlers for events you’re interested in handling. In the observer interface pattern, you’d have to implement all methods in the entire interface including implementing method bodies for notification … Read more

Pros and Cons of Listeners as WeakReferences

First of all, using WeakReference in listeners lists will give your object different semantic, then using hard references. In hard-reference case addListener(…) means “notify supplied object about specific event(s) until I stop it explicitly with removeListener(..)”, in weak-reference case it means “notify supplied object about specific event(s) until this object will not be used by … Read more

What is difference between observer pattern and reactive programming?

Reactive programming is the general paradigm behind easily propagating changes in a data stream through the execution of a program. It’s not a specific pattern or entity per-se, it’s an idea, or style of programming (such as object oriented progamming, functional programming, etc.) Loosely speaking, it’s the concept that when x changes or updates in … Read more

Difference between Observer Pattern and Event-Driven Approach

The Observer Pattern is a very special instance. Event-Driven can mean anything. In most Observer Pattern implementations the Observer is an object watching the observee. When the observee is changed, a method of the observer is called. Strictly speaking this is not an “Event”. That means: various different actions on the observee, usually lead to … Read more

Mediator Vs Observer Object-Oriented Design Patterns

The Observer pattern: Defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically. The Mediator pattern: Define an object that encapsulates how a set of objects interact. Mediator promotes loose coupling by keeping objects from referring to each other explicitly, and it lets you … Read more