OK. I have added two more fields to my registration form - for email and password. So my registration form is having three variables:
nameInput
emailInput
passwordInput
Then I have defined a class with name Registration whose code is as follows:
package objects;
class Registration
{
public function new(name:String, email:String, password:String)
{
this.name=name;
this.email=email;
this.password=password;
}
public var name:String;
public var email:String;
public var password:String;
}
As I have placed this code inside the objects folder and so I have used package objects; at the top of the code.
Then I have defined RegistrationEvent class whose code is as follows:
package events;
import objects.Registration;
import openfl.events.Event;
class RegistrationEvent extends Event {
public static final REGISTER:String = "register";
public function new(type:String, ?registration:Registration) {
super(type, false, false);
this.registration = registration;
}
public var registration:Registration;
}
As I have placed this code inside the events folder and so I written package events; in the beginning of the code.
Then I have used this RegistrationEvent class with the StackItem.withClass function as follows:
var registrationPage = StackItem.withClass(RegistrationPage.ID, RegistrationPage, [
RegistrationEvent.REGISTER => NewAction((event:RegistrationEvent) -> {
var registration = event.registration;
return Push(HomePage.ID, (target: HomePage) -> {
target.registeredRegistration = registration;
});
})
]);
Here I would like to know what is the role of NewAction function? Can you please explain it?
Then inside the HomePage class I have added the following code:
public var registeredRegistration(default, set):Registration = null;
private function set_registeredRegistration(registration:Registration):Registration {
if (this.registeredRegistration == registration) {
return this.registeredRegistration;
}
this.registeredRegistration = registration;
this.setInvalid(InvalidationFlag.DATA);
return this.registeredRegistration;
}
Here my question is when the variable registeredRegistration is defined then why we writing it as registeredRegistration(default, set)? What is the meaning of default and set in this case?
Furthermore what is meaning of the following code:
this.setInvalid(InvalidationFlag.DATA);
Why it is setting it as invalid?
Please reply to my these three questions and then I will move further.