fire a event from qooxdoo, how should I do?
ClassA dispatches the event A of type MyEvent and ClassB listens for that event. Then classB dispatches the same event B of type MyEvent with the same data..
In classB I've made this:
var target = evt.getTarget();
this.fireEvent("A", MyEvent, [target])
but I'm repeating code, it's possible to do it more automated?
thanks a lot
I guess you could enclose this logic inside a qooxdoo global variable and then just call the variable as a function:
var standardEvent : function() {
var target = evt.getTarget();
this.fireEvent("A", MyEvent, [target])
}
and the call it in your subclasses:
qx.core.Init.getApplication().standardEvent();
You'd have to figure out the scope, though.
Related
The following sample code throws an error stating
No exact matches in call to instance method 'bind'
How can I bind the onNext of my publish subject to my observable?
let publish = PublishSubject<Void>()
// Error Here
publish.bind(to: myMethod())
func myMethod() -> Observable<Void> {
return Observable.create{ observer in
observer.onNext(())
observer.onCompleted()
return Disposables.create()
}
}
So what I want is everytime my publish subject emits an onNext event I want to trigger the observable of 'myMethod'
I'm not sure how to interpret this, but it sounds like you want something like:
let publish = PublishSubject<Void>()
let response = publish.flatMap { myMethod() }
response
.bind(onNext: { print($0) })
func myMethod() -> Observable<Void> {
Observable.create{ observer in
observer.onNext(())
observer.onCompleted()
return Disposables.create()
}
}
But it all seems rather pointless since all myMethod() does is emit a next event.
First, the bind(to:) method is in the RxCocoa Framework so you need to add import RxCocoa in your file.
Then, the observable created by myMethod will only be able to emit the event from the .create block. You can't use bind on it. If you need an observable with both the events from your subject and from the myMethod observable, you can do that :
let thirdObservable = Observable.merge(publish, myMethod())
I am having a class extending ReactiveWindowController. As in base class I see this:
// subscribe to listen to window closing
// notification to support (de)activation
NSNotificationCenter
.DefaultCenter
.AddObserver(NSWindow.WillCloseNotification,
_ => deactivated.OnNext(Unit.Default), this.Window);
Hence in my subclass I am writing the callback to remove the observer, as
public partial class SplitViewWindowController : ReactiveWindowController
{
~SplitViewWindowController()
{
Console.WriteLine("Destructor of SplitViewWindowController");
}
public SplitViewWindowController() : base("SplitViewWindow")
{
Console.WriteLine("Constructor of SplitViewWindowController");
this.Deactivated.Take(1).Subscribe(x => {
// NSNotificationCenter.DefaultCenter.RemoveObserver(NSWindow.WillCloseNotification);
// NSNotificationCenter.DefaultCenter.RemoveObserver(this);
//NSNotificationCenter.DefaultCenter.RemoveObserver(Owner);
});
}
But I am lost to find a suitable way to remove the Observer. Or I am doing something wrong here?
Why am I removing the Observer?
The answer is this SplitViewController is not dealloc-ed if any observer remains un-registered. I tried with NSWindowController, here if all the observers are removed, the deallocation works and the destructor's logs prints. If I do not remove observer even in case of subclassing from NSWindowController it doesn't call the destructor.
So the fix is to remove the Observer but how?
Save the observer created and then remove and dispose of it when required:
var observer = NSNotificationCenter.DefaultCenter.AddObserver(NSWindow.WillCloseNotification, HandleAction);
// You can also use the helper method...
// var observer = NSWindow.Notifications.ObserveWillClose(HandleEventHandler);
NSNotificationCenter.DefaultCenter.RemoveObserver(observer);
observer.Dispose();
Can someone please help .
The scenario is that i want to call a new method from inside of other method calls without affecting the processing happening in methods a(),b(),c()
Also, any exception in method newClass.d(id) should not affect processing in a(),b(), c()
ideally would like to call newClass.d(id) after method a() has completed its processing
method a()
{
//calls
method b()
}
#transnational
method b()
{
//calls method c
method c()
}
method c()
{
//this stores some value into database and gets an id
//I need this id and want to call another method d(pass ID)
// i want to call it in a way that if there is any exception in method d(pass ID), its should not affect a(),b(),c()
}
class newClass
{
method d(id)
{
//does something
}
}
Is there any better way of doing this in Spring.
Thanks
Regards
If NewClass is a service/component, and you call it within methodC like
newClassInstance.methodD()
Then i would suggest adding an annotation on methodD
#Transactional(propagation=REQUIRES_NEW)
Doing so, spring will start a new transaction for methodD execution, and if this one fail, it will rollback only changes made in methodD
But, if an exception is thrown from methodD without being catched, it will rollback also previous transaction
I'm trying to use callMethod() from a method executed on the server.
In this case, I should be able to call it in synchronous mode. However, through trial and error I have found that in this context (i.e. on the server), the method requires three parameters rather than the two mentioned in the docs.
It requires
the first parameter to be a string
the second parameter to be an array
the third parameter to be an object
I've tried quite a few combinations with these parameters but nothing seems to work. At the same time, Wakanda doesn't throw an error as long as the parameters are in the correct form.
Any ideas would be more than welcome.
TIA
Let's suppose we have two variable, one containing the name of the dataClass and the second the name of the dataClass's method :
var myDataClass = "User";
var myMethod = "addUser";
To use the dataClass 'User' and call the method 'addUser' you can do it this way :
var currentClass = ds.dataClasses[myDataClass];
currentClass[myMethod]()
The method callMethod() is a clientSide method, it should be used on prototyper Js files.
try to use it on a button.click event :
button1.click = function button1_click (event)
{
ds.User.callMethod({method:"method1", onSuccess:myFunction, onError:failure});
function myFunction(){
return true;
}
function failure(){
return false;
}
};
To call method in a serverSide js File in a synchronous mode, you can just make the call in this manner :
var test = ds.User.method1();
i have a little problem with javafx. i added a change listener like this:
private final ChangeListener<String> pageItemSelected = new ChangeListener<String>()
{
#Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue){
pageGotSelected(newValue);
}
};
now to the problem: if i change an page item like this:
guiPageList.setValue(model.getCurrentTargetPage());
the event gets also(as it get by selecting something with the mouse or key) fired. is there a way to disable the event firing or another way?
i need the event only, if the element got selected by the user and not if i change it with the setValue() function...
perhaps consuming the event, but i donĀ“t know what kind of event this would be.
thanks in advance!!!
You can temporarily remove the listener and add it again:
guiPageList.getSelectionModel().selectedItemProperty().removeListener(pageItemSelected);
guiPageList.setValue(model.getCurrentTargetPage());
guiPageList.getSelectionModel().selectedItemProperty().addListener(pageItemSelected);
Alternatively you could decorate the listener with another listener implementation, the code would be something like:
class InvalidationListenerEventBlocker implements InvalidationListener {
InvalidationListener decoratedListener;
boolean block;
public void invalidated(Observable observable) {
if(!block) {
decoratedListener.invalidated(observable);
}
}
}
Add a setter for the block boolean and send the listener in through the constructor. Set block to true to stop events.
This is very old question, but I came to some solution I personally use, that's reusable and does not require storing a reference to the listener (but it needs a reference to the exposing/muffling property thou).
So first the concept: we're going to create lambda (InvalidationListener), that is going to be called only if above mentioned exposing/muffling property is set to true/false. For that we are going to define another functional interface that provides described behavior:
#FunctionalInterface
private interface ManageableInvalidationListener
extends InvalidationListener {
public static InvalidationListener exposing(
BooleanProperty expose,
ManageableInvalidationListener listener) {
return ob -> {
if (expose.get()) {
listener.invalidate(ob);
}
};
}
public static InvalidationListener muffling(
BooleanProperty muffle,
ManageableInvalidationListener listener) {
return ob -> {
if (!muffle.get()) {
listener.invalidated(ob);
}
}
}
public abstract void invalidated(Observable ob);
}
This interface defines two static methods we're going to use in our code. We pass a steering property as first argument (it will tell if listener should be called) and actual implementation to be performed, when it will be called. Please note, that there is no need to extend InvalidationListener, but I'd like to keep ManageableInvalidationListener in sync with InvalidationListener.
So we would call exposing if we need to create a (manageabale) listener that would notify the (invalidation) listener if expose property has value of true. In other case we would create the listener with muffling, if true of the steering property would mean, well, to muffle the notification.
How to use it?
//- Let's make life easier and import expose method statically
import static ManageableInvalidationListener.exposing;
// ...
//- This is the steering property.
BooleanProperty notify = new SimpleBooleanProperty(true);
//- This is our main property with the listener.
ObjectProperty<Foobar> foobar = new SimpleObjectProperty<>();
//- Let's say we are going to notify the listener, if the
// notify property is set to true.
foobar.addListener(exposing(notify, ob -> {
//- Here comes the InvalidListener code.
}));
And then somewhere in the code:
//- Listener will be notified as usual.
foobar.set(new Foobar());
//- Now temporarily disable notifications.
notify.set(false);
//- The listener will not get the notification this time.
foobar.set(new Foobar());
//- Re-enable notifications.
notify.set(true);
Hope this somehow helps. You're free to use the code in this post as pleases you.