I register object in parent class but subscribe events in child class, yet it still works why? - event-bus

So this is exactly how I want it to work but I'm just confused on why it works. I register the object in parent class but subscribe events in child class.
By registering the object in the parent class, wouldn't EventBus be seeing type parent class(only events subscribed in parent class)?
If that's the case, how is it able to see the events that are subscribed in child class then?
If someone can clarify this that would be awesome thanks!

"No, the child classes inherit the parent's methods. But the type when register(class) is called at runtime will be the type of the child, not the parent (class instanceOf Child). Hence EventBus only discovers the #Subscribed methods in the child class."

Related

Clean way to get mousePressed event notified to QGraphicsView

I inherited from QGraphicsItemGroup and made a class that keeps a pointer to its contained items so that I can later refer to them and change properties. It has an ellipse item and a line item and I want only the ellipse to be clickable. I need that press event of the ellipse to propagate to the QGraphicsView so that I can send a signal to some surrounding widgets.
So far I tried inheriting also from QGraphicsObject to have signals available but got stuck with ambigous base error when trying to use scene->addItem. I tried casting to QGraphicsItemGroup but I still get the error. I also tried inheriting from QObject with no success.
I'm new to QGraphics and I know the QGraphics framework has a lot of tools for user interaction and even interaction between GraphicsItems but this is really kicking my butt.
What would be the proper way to get this behavior?
Create a separate "emitter" class
To allow your subclass of QGraphicsItemGroup to emit signals, you can create a separate "emitter" class that inherits from QObject. Then, you can add an instance of this emitter class within your subclass of QGraphicsItemGroup. The emitter object can then emit signals for your subclass as needed.
QGraphicsItemGroup is treated as a single item
Unfortunately, an instance of QGraphicsItemGroup is treated as a single item, so each mousePressEvent will belong to the entire group rather than one of the members of that group (i.e., the ellipse item or the line item). If you want the mousePressEvent to behave differently depending on which item is clicked, they will need to be separate items, or you could try using line->setParentItem(ellipse) to link up the 2 items without using QGraphicsItemGroup.

Get all the classes that extend a main class

So, if I had something like
class Event {// . . .}
class Children extends Event {// . . .}
class Second extends Event {// . . .}
Would there be any way to retrieve the Children and Second class objects, using the the parent class Event?
Would there be any way to retrieve the Children and Second class objects, using the parent class Event?
No. Given just the code you show, there would not be any way to identify all subclasses of Event in plain Javascript. A parent object is not informed in any way when a subclass is defined, nor is any global catalog maintained. A subclass definition stands on its own and the fact that it subclasses/extends the Event class is not saved anywhere or registered anywhere. It's just information that is used when an instance of the subclass is actually created.
If you wanted to manually keep track of such a thing, you could create your own catalog of sub-classes and then make your code register everything in that catalog.

How to pass Child Component state to Store without interacting with parent component using Ngxs-store?

I want to pass a child component state to Store without interacting with a parent component in NGXS-Store?
previous I have pass child state to parent using EventEmmiter, Inside parent component Html take and then parent component pass child component state to Store ......But now I need to pass child component state to directly Store not Interacting with parent component
You dispatch an action to update state. You can do that from the child component exactly as you would in the parent component. If you're asking something else then an example of what you are trying to do would be helpful.

Inherited IBOutlets vanish after changing layout to constraints

Scenario:
A Child UIViewController inherits some IBOutlets from its parent UIViewController (which doesn't have its own XIB).
Hence we have child+parent IBOutlets linked to the child's Interface Builder (XIB).
Originally, within a frame-based layout paradigm, I could link BOTH sets of IBOutlets from the child UIViewController's XIB as a single list.
However, apparently, after converting to a constraint-based layout, the XIB can't see the inherited IBOutlets; only the local (File's Owner) IBOutlets can still be seen.
That is, the IB complains that the File's Owner (the child UIViewController) does not have the inherited IBOutlets.
Question:
1) Is it proper to inherit IBOutlets from a parent UIViewController and if true, how do I fix this?
... or, must all IBOutlets be declared (as local IBOutlets) in the de-facto "File's Owner" (which in this case is the child UIViewController)?
The IB's "File's Owner" was linked to a vestigial class that had been renamed.
Hence the loss of IBOutlets.

Monotouch -- Changing label text in ViewController from another class?

I have a class that functions as an async TCP Client. In that class, I have a callback function, such as Client_Connected. This fires when my TCP Client has been connected. In my main viewcontroller class, I have an instance of the TCPClient and a label that I want to display the status of the tcpclient.
My question is, in the callback function of the tcpclient class, how can I reference and set the label's text in my mainviewcontroller's class?
When you create your TCPClient class, pass in a reference to your parent class (or just a reference to the label you want to update) - then your "child" class will have access to the element on the "parent" that needs to be updated.
There are probably other approaches, but this is fairly common.

Resources