observer-pattern

How do I modify existing AS3 events so that I can pass data?

柔情痞子 提交于 2019-12-05 22:39:11
问题 So I want a way to set up events so that I can pass data without creating closures \ memory leaks. This is as far as I have got: package com.events { import flash.events.Event; public class CustomEvent extends Event { public static const REMOVED_FROM_STAGE:String = "removedFromStage"; public var data:*; public function CustomEvent(type:String, customData:*=null, bubbles:Boolean=false, cancelable:Boolean=false) { super(type, bubbles, cancelable); this.data = customData; } public override

How to implement the Observer pattern with Java RMI?

早过忘川 提交于 2019-12-05 18:22:14
问题 I have a client that starts a long running process on the server. At regular intervals, I'd like to show the user what's happening in the background. The most simple approach is to poll the server but I'm wondering if there wasn't a way to implement the Observer pattern for this. Unfortunately, I'm using RMI to talk to the server and I fear that I have to turn my client into an RMI server for this. Is there another way that I'm missing? 回答1: http://sites.google.com/site/jamespandavan/Home

How to set an Observer to Update Navigation Drawer after onActivityResult method's received an Intent result

依然范特西╮ 提交于 2019-12-05 18:17:00
In my app I want to update the Navigation Drawer with the username's nickname and email after he's logged in. From my MainActivity I am starting a LoginActivity with the startActivityForResult(intent, PICK_ACCOUNT_REQUEST); method to get the users registered or logged in. After the LoginActivity returns the Intent data result (his NAME and EMAIL ) back to MainActivity , the method onActivityResult() is called and there I try to update the class' global variables NAME and EMAIL with the newly received data, with no success: after every registration or log the two fields never show in the

Different ways of observing data changes

一世执手 提交于 2019-12-05 16:27:22
In my application I have many classes. Most of these classes store quite some data, and it is important that other modules in my application are also 'updated' if the content of one of the data classes changes. The typical way to do this is like this: void MyDataClass::setMember(double d) { m_member = d; notifyAllObservers(); } This is a quite good method if the member is not often changed and the 'observing classes' need to be up-to-date as fast as possible. Another way of observing the changes is this: void MyDataClass::setMember(double d) { setDirty(); m_member = d; } This is a good method

Observable closed on error

ε祈祈猫儿з 提交于 2019-12-05 15:52:24
I have an issue with Observable in Angular 2. I subscribe my component to an observable, then when my service has new value, my component is notified. Problem is when the observer push an error, like an HTTP error, my observable is closed, so my component is no more notified. Question How can I do to make my component continue listening my service even when I have an error ? Example Here an example Here my code : Component constructor(private appService: AppService) { //I subscribe my component to an observable this.appService.commentsObservable.subscribe((comments) => { console.log(comments);

Knockout's mapping breaks observable arrays

断了今生、忘了曾经 提交于 2019-12-05 13:15:22
I'm experiencing a strange problem with Knockout's mapping plug-in. If I fill an observable array through mapping I can't iterate the array or get its length, even though the UI is updated correctly, the array seems empty. You can find a working jsFiddle here: http://jsfiddle.net/VsbsC/ This is the HTML mark-up: <p><input data-bind="click: load" type="button" value="Load" /></p> <p><input data-bind="click: check" type="button" value="Check" /></p> <table> <tbody data-bind="foreach: items"> <tr> <td data-bind="text: name"></td> <td data-bind="text: value"></td> </tr> </tbody> </table> <p data

MVC and Observer pattern

◇◆丶佛笑我妖孽 提交于 2019-12-05 07:19:52
问题 I am having problems with implementing Observer pattern in my project. The project has to be made as MVC in C#, like a Windows application. In my domain model I have for example Country class and Country repository. I have a Country controller and views for seeing all countries(a list on a form), adding new country, and editing existing country. I don't know how many views will have to know about changes connected with changing Country. The thing is I have to use Observer pattern. And on the

Making a JFrame and Observable Object

让人想犯罪 __ 提交于 2019-12-05 05:35:13
I have a class let's say MyJFrame which represent the GUI of my application. It implements the interface Observer and override the method update . public class MyJFrame extends JFrame implements Observer{ ... public void update(Observable arg0, Object arg1){ ... } } Now I want to make also my JFram an Observable object but I can't because it already extend the class JFrame . I tried to create a variable of type Observable in my class. public class MyJFrame extends JFrame implements Observer{ Observable observable = new Observable(); The problem here is that I can add Observer to this

Is it possible to add observer to tableView.contentOffset?

家住魔仙堡 提交于 2019-12-05 04:43:02
I need to track tableView.contentOffset.y Is it possible to add observer to tableView.contentOffset? I think this is impossible because contentOffset doesn't inherit NSObject class. Is any other solution? UITableView is a UIScrollView subclass so you can use the UIScrollViewDelegate method scrollViewDidScroll: to be notified when the view scrolled. Check the contentOffset of the scrollView in that method contentOffset is a key path, so you can also observe its changes using KVO [self.tableView addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew |

RxJava timer that repeats forever, and can be restarted and stopped at anytime

丶灬走出姿态 提交于 2019-12-04 23:14:44
In android i use Timer to execute task that repeats every 5 seconds and starts after 1 second in this way: Timer timer = new Timer(); timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { // Here is the repeated task } }, /*Start after*/1000, /*Repeats every*/5000); // here i stop the timer timer.cancel(); this timer will repeat Until i call timer.cancel() I am learning RxJava with RxAndroid extension So i found this code on internet, i tried it and it doesnt repeat: Observable.timer(3000, TimeUnit.MILLISECONDS) .subscribeOn(Schedulers.newThread()) .observeOn