v-bind strips methods of passed class instance object - vue.js

When i pass a class instance object to a slot wit v-bind all methods are stripped from the object.
<slot v-bind="classInstanceObject"></slot>
I just want the real object to be passed in a un-modified way. How can i do that?

Related

EMF-JSON: Include properties of EObject Subclass

I am using EMF-JSON for serializing an EMF model instance. The problem is, that a subclass of EObject gets treated as such and not as the subclass. Thus, properties in the subclass get lost during serialization, as the EObjectSerializer is selected. How can I make sure that the properties of the subclass are included without changing the class itself (referring to the inclusion annotations)? In the following you find the generated interfaces. In this case, the ref property of the ArithVar class is not serialized.
public interface ArithExpr extends EObject {}
public interface ArithVar extends ArithExpr {
VarType getRef();
void setRef(VarType value);
}
public interface VarType extends EObject {}
Any ideas?
From the documentation:
References are by default serialized as JSON objects that contain two fields. The first field is the type of the referenced object and the second field is the URI of the referenced object. The type field is named eClass and the URI field is named $ref.
So my guess is it should work by default. Have you tried debugging through EObjectSerializer ? My guess is it probably uses the EMF reflective API to iterate through all the features of an EObject and serialize them.

Aurelia #bindable *Changed calls on initialisation

I'm finding that when I define a #bindable property, and a propertyChanged handler for it, it sometimes gets called before the custom component's bind() method and sometimes doesn't.
https://gist.run/?id=d7d9e7c7080f581f8e81b888268a2f11
In several places, I'm using these propertyChanged handler on one property to trigger updates to another, in situations where a #computedFrom isn't appropriate, as the second value is a complex calculation that I don't want called multiple times.
For now, I'm having to do the following:
#bindable propOne;
#bindable propTwo;
propOneChanged(newVal) {
propTwo = "something complex " + newVal;
}
bind() {
** propOneChanged(propOne);**
}
Is there any better way to do this (e.g. something in the #bindable decorator) so that I don't need to manually 'prime' the property in the bind()?
Is there any better way to do this (e.g. something in the #bindable decorator) so that I don't need to manually 'prime' the property in the bind()?
No.
If you don't have a bind() method, then Aurelia will call your change handlers during bind(). Unless you've got specific things you need to do (besides priming your bindables), remove the bind() method. Then you don't need to worry about this.
If you do have a bind() method, then that's the correct place for you to invoke your change handlers.
Also, I get the impression you're not entirely sure how bindables work.
Simply put: a #bindable decorator tells the Aurelia framework to wrap that property in a get + set method (this happens when the component is loaded, way before its lifecycle).
The set method invokes the change handler whenever it receives a value that's different from the current value - when you assign a value to a bindable, the change handler is invoked, regardless of whether the component is bound, even if it's not a ViewModel.
So to address your comment:
it sometimes gets called before the custom component's bind() method and sometimes doesn't.
It will be called before the custom component's bind() method if and only if you assign some value to it before the custom component's bind(). For example, in the constructor or in the property initializer.
the xyChanged protoype is xyChanged(newValue, oldValue). To prevent unwanted behaviour i'm always doing
if(oldvalue === null) return;
(which is null directly after bind()). If you use async model-requests its in most cases meaningfull to do a null check in your view
<div if.bind="model.data">...</div>

method overriding for member variable

My understanding is that we can't override the member variable but when i am running the below program, i am getting unexpected o/p
class Parent {
String message = "parent";
void say() {
System.out.println(message);
}
}
class Child extends Parent {
String message = "child";
}
public class Test {
public static void main(String[] args) {
new Child().say();
}
}
In the o/p i am getting "parent" While we are calling the say method using child object and even there is no Parent reference.
Can anybody help me to understand it.
Thanks
The "say" method is on the parent class, not on the child. So when it call for the "message" member it looks at his own, not at the child's one. The fact that the call is make through a child class has nothing to do in it.
Indeed, the member variable is not overriden here. This is expected behavior.
EDIT :
The Java Language Specification says that "If the class declares a field with a certain name, then the declaration of that field is said to hide any and all accessible declarations of fields with the same name in superclasses, and superinterfaces of the class."
"Inherit" does not mean "copy". When you call the "say" method on a child instance, is not a "code copy" of the method that is called, but the method of the parent class, as it is defined in the parent class. And the parent class know nothing about the child variable member.
your child class is extend parent class features! so child class has say method by default and it's value (parent) because parent class say method will called when you call say method from child object. if you want to print "child" instead, you need override your say method in the child class and change that default feature, which extends from parent class.

REALBasic/Xojo NilObjectException When Calling Class Method From Property

I'm writing a console application used for UDP-based chat.
I have a class called App whose Super is ConsoleApplication (the "main" class) and a UDPInterface class whose Super is EasyUDPSocket. In the App class, there is a property called UDP whose type is UDPInterface (UDP As UDPInterface). In the Run event handler, there is this code:
StdOut.WriteLine(UDP.GetIP)
UDPInterface's method GetIP consists of the following code (return type is String):
return LocalAddress
LocalAddress is an EasyUDPSocket method that simply retrieves the internal IP.
The problem I'm having is that when I call UDP.GetIP, the program returns a NilObjectException. I need to use the UDPInterface class as a property so its properties work the same across all the methods inside App.
Objects must be instantiated using the New keyword prior to use. An object which hasn't been instantiated will always be Nil, and using a Nil object will always raise a NilObjectException:
UDP = New UDPInterface
StdOut.WriteLine(UDP.GetIP)

groovy method scope when using a method reference

I have a groovy class that looks up a method reference and then invokes it. The method being invoked is a private method. When the actual class is an instance of the child class, it throws an error that it cannot find the private method, even though it is the public method in the parent that actually calls it.
In this case, I could obviously just call pMethod2() directly and that works, but I'm trying to understand why this doesn't work as written and if there's a way to correct it so it works.
class Parent {
def pMethod1() {
def m = this.&pMethod2
m() // this call fails if the calling class is of type Child
}
private def pMethod2() {}
public static void main(String[] args) {
new Child().pMethod1();
}
}
class Child extends Parent {}
It is a bit confusing, especially if you're used to C / C++. What you get when using the ".&" operator in Groovy is not an address, but an instance of MethodClosure.
The MethodClosure object contains an owner and a delegate object, which is used when resolving the method to call. In your example, the owner and delegate object will be "this", which is an instance of Child. The method to call is simply stored as a string.
So, the assignment
m = this.&pMethod2
is just a shorthand way of writing
m = new MethodClosure(this, "pMethod2")
When you invoke the m() closure, it will try to resolve (at runtime) the method by looking for methods named "pMethod2" in the owner and the delegate objects respectively. Since the owner and delegate is an instance of Child, it will not find private methods located in Parent.
To make your example work you must make sure that the method is visible to the owner and/or delegate of the closure.
This can be done several ways, for instance by changing the access modifier of pMethod2 to protected, or by creating the closure with an instance of Parent; something like this:
m = new Parent().&pMethod2
Note that is is irrelevant that you created the MethodClosure instance in a method where pMethod2 is actually visible. It is also irrelevant that you invoke the closure in a method where it is visible. The method is not visible to the owner or delegate of the MethodClosure, which is what is being used when resolving the method.