I am not so sure how to implement a model which can share its state between several requests. I mean a model which holds a set of data not only a model which describes how the data looks like.
An example would be a quizz or a survey where the user steps through a couple of questions and each question is requested via an next or prev route in a subcontroller where the response or selected value of the user would be stored in a model and only at the end saved (to a db or a file).
I can inject the model to the UfrontJSApplication, and have then access in every route in the controller but then my api doesn't know anything about it. I can't store it inside the api because it's recreated on every new request.
The idea is like this:
class SurveyController extends Controller {
@inject public var surveyApi:app.api.AsyncSurveyApi;
@inject public var surveyModel:SurveyModel; // injected into UfrontJsApplication
@:route("/nextQuestion")
public function doNextQuestions(args: { index:Int } ) {
surveyModel.add(/*an item from the post vars*/);
return surveytApi.getNextQuestion(args.index) >> function(questionVO):ViewResult {
return new ViewResult(questionVO) );
};
}
//called after the last question via a button finish for example
@:route("/saveSurvey")
public function doSaveSurvey() {
//save the entire model filled up by every doNextQuestion route
return surveytApi.save(/*can't pass my model here*/) >> function(message):RedirectResult {
return new RedirectResult(message) );
};
}
}
Any thoughts about this? Maybe a solution should be implemented completely differently?
P.S. Perhaps someone with at least 1500 reputation can create an 'ufront' tag ?