first implementation of Cairngorm
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
package model;
|
||||
|
||||
import vo.Rider;
|
||||
import feathers.data.ArrayCollection;
|
||||
import openfl.errors.Error;
|
||||
import openfl.events.Event;
|
||||
import com.adobe.cairngorm.model.IModelLocator;
|
||||
import openfl.events.EventDispatcher;
|
||||
|
||||
class AppModelLocator extends EventDispatcher implements IModelLocator {
|
||||
|
||||
// events constants
|
||||
public static final VIEWING_CHANGE = "viewingChange";
|
||||
public static final RIDERS_LIST_DP_CHANGE = "ridersListDPChange";
|
||||
|
||||
|
||||
// this instance stores a static reference to itself
|
||||
private static var model:AppModelLocator;
|
||||
|
||||
// available values for the main viewstack defined as constants to help uncover errors at compile time instead of run time
|
||||
public static final ADMIN_LOGIN = 0;
|
||||
public static final RIDERS_LIST = 1;
|
||||
public static final RIDER_DETAIL = 2;
|
||||
|
||||
// viewstack starts out on the admin login screen
|
||||
public var viewing(default, set):Int = ADMIN_LOGIN;
|
||||
|
||||
private function set_viewing(value:Int):Int {
|
||||
viewing = value;
|
||||
dispatchEvent(new Event(VIEWING_CHANGE));
|
||||
return viewing;
|
||||
}
|
||||
|
||||
// rider object contains uid/passwd
|
||||
// its value gets set at login and cleared at logout but nothing binds to it or uses it
|
||||
// retained since it was used in the original Adobe CafeTownsend example app
|
||||
/*public var user(default, set):User;
|
||||
|
||||
private function set_user(value:User):User {
|
||||
user = value;
|
||||
dispatchEvent(new Event(USER_CHANGE));
|
||||
return user;
|
||||
}*/
|
||||
|
||||
// contains the main riders list which is populated on startup
|
||||
// mx:application's creationComplete event is mutated into a cairngorm event
|
||||
// that calls the httpservice for the data
|
||||
public var ridersListDP(default, set):ArrayCollection<Rider>;
|
||||
|
||||
private function set_ridersListDP(value:ArrayCollection<Rider>):ArrayCollection<Rider> {
|
||||
ridersListDP = value;
|
||||
dispatchEvent(new Event(RIDERS_LIST_DP_CHANGE));
|
||||
return ridersListDP;
|
||||
}
|
||||
|
||||
// variable to store error messages from the httpservice
|
||||
// nothinng currently binds to it, but an Alert or the login box could to show startup errors
|
||||
public var errorStatus:String;
|
||||
|
||||
|
||||
// singleton: constructor only allows one model locator
|
||||
public function new() {
|
||||
super();
|
||||
if (AppModelLocator.model != null) {
|
||||
throw new Error("Only one ModelLocator instance should be instantiated");
|
||||
}
|
||||
}
|
||||
|
||||
// singleton: always returns the one existing static instance to itself
|
||||
public static function getInstance():AppModelLocator {
|
||||
if (model == null)
|
||||
model = new AppModelLocator();
|
||||
return model;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user