Questions tagged [observers]

An object which registers itself to listen for updates on another object

In an , observers register themselves with a subject. The subject notifies each of its observers about updates to itself, usually by calling a method on the observers.

911 questions
215
votes
10 answers

When should we use Observer and Observable?

An interviewer asked me: What is Observer and Observable and when should we use them? I wasn't aware of these terms, so when I got back home and started Googling about Observer and Observable, I found some points from different resources: 1)…
Ravi
  • 30,829
  • 42
  • 119
  • 173
119
votes
17 answers

LiveData remove Observer after first callback

How do I remove the observer after I receive the first result? Below are two code ways I've tried, but they both keep receiving updates even though I have removed the observer. Observer observer = new Observer() { @Override …
galaxigirl
  • 2,390
  • 2
  • 20
  • 29
31
votes
3 answers

Using property observers on NSManaged vars

I have a var declared in a class like so: @NSManaged var isFavorite: Bool I would like to declare a property observer, very similar to the one below. var organization: String { didSet { postNotificationWithName( "newData" ) } …
Satre
  • 1,724
  • 2
  • 18
  • 22
20
votes
1 answer

Does ResizeObserver invoke initially on page load?

Seems when I pass a node to ResizeObserver.observe() on DOMContentLoaded event, it invokes immediately. Is it considered a normal behavior?
user11217778
20
votes
4 answers

Are there any Observers written In RecyclerView.Adapter to know if dataset has been changed?

I have implemented my RecyclerView with it's Custom Adapter as follows Global Declarations as follows private LinearLayoutManager linearLayoutManager; private int pastVisibleItems, visibleItemCount, totalItemCount; private CustomRecyclerViewAdapter…
Nikhil
  • 3,711
  • 8
  • 32
  • 43
17
votes
3 answers

Is removing a NotificationCenter observer that was created with closure syntax by name adequate?

I have a few notifications that were created using block / trailing closure syntax which look like this: NotificationCenter.default.addObserver(forName: .NSManagedObjectContextObjectsDidChange, object: moc, queue: nil) { note in //…
Dan Beaulieu
  • 19,406
  • 19
  • 101
  • 135
15
votes
3 answers

Firebase: when to call removeObserverWithHandle in swift

Documentation says you need to call observeEventType:withBlock to remove an observer if you no longer need it. I've seen samples where it is called within ViewDidDisAppear. I also find some Obj-C code called this method within deinit, which is…
User5103156
  • 223
  • 1
  • 3
  • 7
15
votes
2 answers

Data binding in a dynamically inserted polymer element

There're some times when we could need adding a custom element dynamically into a context. Then: The inserted polymer could receive some properties bound to another property inside the context, so it can change accordingly. At polymer 0.5 we could…
recluising
  • 348
  • 1
  • 3
  • 13
14
votes
4 answers

Laravel. Disable observer methods if the database is seeding

I have an observer for my User model. Inside my observer->created event i have some code. public function created(User $user) { sendEmail(); } So, the idea is, when a user is created, the system will send for the user email notification that…
14
votes
2 answers

How do you set the sort order for event observers in Magento?

I have created an observer on the catalog_product_save_after event, but it seems to be getting called before the catalogrule observer that runs the applyAllRulesOnProduct() method. I need to call mine after applyAllRulesOnProduct() runs. How is…
Scruffy Paws
  • 1,219
  • 1
  • 21
  • 27
13
votes
1 answer

In an Observer method, how do you tell Magento to not process code after the dispatched event

I have some code in the checkout where I set a key in the session if that key is set to false anywhere in the checkout I need to send them back to the billing page. I have the code for it, but I also can't have any of the code that is typically ran…
dan.codes
  • 3,523
  • 9
  • 45
  • 59
13
votes
1 answer

Broadcasting eloquent events using observers

Currently I am using observers to handle some stuff after creation and updating of my models. I want to update my app by making it real-time using laravel-echo but I am not able to find documentation regarding the use of laravel-echo in combination…
milo526
  • 5,012
  • 5
  • 41
  • 60
12
votes
4 answers

How to detect switch between macOS default & dark mode using Swift 3

I want to change my status bar app icon when the user switches from default to dark mode and vice versa (using Swift 3). Here’s what i have so far: func applicationDidFinishLaunching(_ aNotification: Notification) { …
12
votes
1 answer

Exact place to register observer in Laravel 4

When using a separate class for a model observer, where exactly should I register the observer? The documentation says to call User::observe(new UserObserver); but I’m not sure where the best place to do this would…
Gowtham Selvaraj
  • 478
  • 1
  • 5
  • 12
12
votes
6 answers

SQLSTATE[HY000]: General error: 2006 MySQL server has gone away on running cron job magento

I am working on Magento site and I get this error: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away on running cron job magento I only get this error sometimes.
Mahmood Rehman
  • 4,303
  • 7
  • 39
  • 76
1
2 3
60 61