SinglePageAppSinglePageApp is a way to create simple, one page applications. For example, a search engine is a one page application, containing a form (search keyword and submit button) and results. Look in SinglePageTurtleApp for another example.
A word about modules:SinglePageApp is a Comanche module. To start Comanche with a module, do this:
"ChieftainModule turtleExample" | service chief | chief := ChieftainModule new initialize. chief mapPrefix: '/comanche/objects' to: ObjectUrlMap; mapPrefix: '/turtle' to: (SinglePageTurtleApp new initialize). service := ComancheNetService named: 'basicExample' onPort: 8000. service module: chief. service start
ObjectUrlMapMaintains a list of URLs pointing to objects. Instead of manually assigning URLs to objects, allows automatic assignment. Currently, it object-to-URL mapping is implemented on the class side, primarily to simplify things (don't have to worry about which map goes with which server), but the next revision will make it possible to have a separate object-to-url map for each server.
ObjectUrlMap is added to the modules first so that it can serve objects even if subsequent modules seize control (i.e., don't check for the request URL and process all requests).
Defines form fields, both for rendering the form and for processing it. Format is an array of tuples. Each tuple is (name type) (In Comanche 5, this was enhanced to support selection lists). Name is used for the form field name. Type is used to render the field and to convert from the string (when form is submitted). Currently supported types include: Integer, String, SubmitButton, SelectionList (Comanche 5). Integer and String convert to the corresponding Smalltalk classes. SubmitButton is either false or true (true if it was pressed to submit the form).
Also see #getParameter:from:
#getParameter: paramName from: request
Retrieves the parameter paramName from the request and converts it according to the specification in #inputFields
SPTA adds two instance variables to SinglePageApp): form and pen. Here, they are initialized. The form is added to the output (which is used by SinglePageApp>>asHtmlDocumentForRequest: for rendering the page). The pen is "invisible", but is necessary to perform turtle graphics. (Alternatively, we could have created a TurtleForm subclass of Form, which would understand turtle commands).
#( (amount Integer) (forwardButton SubmitButton) (leftButton SubmitButton) (rightButton SubmitButton) )
This method shows what #process: would have looked like with Compiler support. A pragma could be a syntactic sugar for making access to form fields easier. The pragma can be made even simpler (just
This is where the actual processing is done right now. The first four lines retrieve parameters specified in #inputFields. Since SubmitButtons are true when they are pressed, this fact is used for control flow. The method returns nothing explicitly, thus it implicitly returns self. Since SPTA is a module, the result of its #process: will be picked up by Comanche and converted into HTML by sending it a #asHtmlDocumentForRequest: message, which SPTA inherits from SinglePageApp.
Link to this Page