Prev | Current Page 812 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

To illustrate the
use of AsyncProxy and to resume what has been discussed so far, here is a more complex and
real example.
On the server side is a database of persons. Those persons can have parents and children referenced
using a unique numeric identifier. The Person object also keeps record of the year of birth. To
alleviate the sample code, the PersonDatabase class is hard coded with its example data, but
the code can be easily adapted to load such data from a real database using SPOD or a direct
SQL connection.
On the client side a JavaScript interface is implemented using an AJAX technique. Every time a link to
a person in the page is selected, the data of this person is loaded from the server and applied on the page
without the need to reload the entire page.
The Person class is very simple and it is used as a specialized data container, as shown in the
following example:
typedef PersonId = {
id : Int,
name : String
}
class Person
{
public var id(default, null) : Int;
public var name : String;
public var birthyear: Int;
public var father : Null < PersonId > ;
public var mother : Null < PersonId > ;
Chapter 15: Putting It All Together with haXe Remoting
439
public var children(default, null) : List < PersonId > ;
public function new(id : Int, name : String, birthyear : Int)
{
children = new List();
this.


Pages:
800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824