observer-pattern

Scala Listener/Observer

送分小仙女□ 提交于 2019-11-29 01:07:52
问题 Typically, in Java, when I've got an object who's providing some sort of notification to other objects, I'll employ the Listener/Observer pattern. Is there a more Scala-like way to do this? Should I be using this pattern in Scala, or is there something else baked into the language I should be taking advantage of? 回答1: You can still accumulate a list of callbacks, but you can just make them functions instead of having to come up with yet another single method interface. e.g. case class MyEvent

Reactive Extensions for .NET (Rx) in WPF - MVVM

冷暖自知 提交于 2019-11-28 23:05:23
问题 I am using Reactive extensions for NET (Rx) with Caliburn.Micro in my WPF app. I'm trying to port my WPF app to use an MVVM architecture and I need to monitor changes in the Text property of a TextBox control. If the last change of the Text property was more than 3 seconds ago I need to call the LoadUser method of a service. Porting the logic from my old solution to the new solution with MVVM architecture. OLD XAML: <TextBox Name="Nick" Grid.Row="0" FontSize="14" Margin="2,2,2,2"

Jquery Observer pattern

放肆的年华 提交于 2019-11-28 20:57:45
I've been looking over the internet for examples of implementing the observer pattern in jquery. I would like to have it like this observer1.observe(subject); observer2.observe(subject); Define some custom event callbacks for the observers observer1.bind('customEvent', function(contextData) { //Some code }); observer1.bind('anotherCustomEvent', function(contextData) { //Some code }); observer2.bind('customEvent', function(contextData) { //Some code }); The following line would then trigger the customEvent callbacks of both observers subject.trigger('customEvent', contextData); while the

How to trigger an event on payment received in magento?

佐手、 提交于 2019-11-28 20:57:00
Greetings, in Magento I want to trigger an event, once an order has been set to processing (by gateway confirmation or manually) that, example: If a general customer (id 1) spends over 100$ and the payment has been confirmed, set his group id to 4 (silver VIP, which by promotion rule gets 2% discount globally) I would give a bounty to this, but I'd like the answer before 2 days O_o EDIT : the answer I received so far is only a partial answer, also I find the links very confusing, I'm not clear on what is the minimal setup, what do i have to configure create etc... Also I'm trying to find out

Android Rxjava subscribe to a variable change

帅比萌擦擦* 提交于 2019-11-28 20:22:22
I am learning Observer pattern, I want my observable to keep track of a certain variable when it changes it's value and do some operations, I've done something like : public class Test extends MyChildActivity { private int VARIABLE_TO_OBSERVE = 0; Observable<Integer> mObservable = Observable.just(VARIABLE_TO_OBSERVE); protected void onCreate() {/*onCreate method*/ super(); setContentView(); method(); changeVariable(); } public void changeVariable() { VARIABLE_TO_OBSERVE = 1; } public void method() { mObservable.map(value -> { if (value == 1) doMethod2(); return String.valueOf(value); })

Observers vs. Callbacks

痞子三分冷 提交于 2019-11-28 17:13:35
i thought about using observers or callbacks. What and when you should use an observer? F.e. you could do following: # User-model class User << AR after_create :send_greeting! def send_greeting! UserNotifier.deliver_greeting_message(self) end end #observer class UserNotifier << AR def greeting_message(user) ... end end or you could create an observer and let it watch when users becomes created... What dou you recommened? A callback is more short lived: You pass it into a function to be called once. It's part of the API in that you usually can't call the function without also passing a callback

How to create a full Audit log in Rails for every table?

谁说胖子不能爱 提交于 2019-11-28 16:54:00
We recently began a compliance push at our company and are required to keep a full history of changes to our data which is currently managed in a Rails application. We've been given the OK to simply push something descriptive for every action to a log file, which is a fairly unobtrusive way to go. My inclination is to do something like this in ApplicationController : around_filter :set_logger_username def set_logger_username Thread.current["username"] = current_user.login || "guest" yield Thread.current["username"] = nil end Then create an observer that looks something like this: class

How would you test observers with rSpec in a Ruby on Rails application?

让人想犯罪 __ 提交于 2019-11-28 16:14:54
问题 Suppose you have an ActiveRecord::Observer in one of your Ruby on Rails applications - how do you test this observer with rSpec? 回答1: You are on the right track, but I have run into a number of frustrating unexpected message errors when using rSpec, observers, and mock objects. When I am spec testing my model, I don't want to have to handle observer behavior in my message expectations. In your example, there isn't a really good way to spec "set_status" on the model without knowledge of what

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

那年仲夏 提交于 2019-11-28 15:55:14
问题 I've got the following (simplified): interface IFindFilesObserver { void OnFoundFile(FileInfo fileInfo); void OnFoundDirectory(DirectoryInfo directoryInfo); } class FindFiles { IFindFilesObserver _observer; // ... } ...and I'm conflicted. This is basically what I would have written in C++, but C# has events. Should I change the code to use events, or should I leave it alone? What are the advantages or disadvantages of events over a traditional observer interface? 回答1: Consider an event to be

Why should the observer pattern be deprecated?

最后都变了- 提交于 2019-11-28 15:35:35
I've noticed that my dependency injected, observer-pattern-heavy code (using Guava's EventBus ) is often significantly more difficult to debug than code I've written in the past without these features. Particularly when trying to determine when and why observer code is being called. Martin Oderski and friends wrote a lengthy paper with an especially alluring title, "Deprecating the Observer Pattern" and I have not yet made the time to read it. I'd like to know what is so wrong with the observer pattern and so much better about the (proposed or other) alternatives to lead such bright people to