From: Sean P. <sea...@ma...> - 2005-03-12 02:54:08
|
On Mar 11, 2005, at 5:10 PM, Ralph Thomas wrote: > Hi there, > > I (think that I) want to add a new type to Adam. My program is MVC > based, and the model is always instanciated from a string (a URL or > serialized model). I understand that I could define a sheet like: > > sheet my_model { > interface: > name : ""; > mime_type: ""; > parent : ""; // will be the model's parent's serialized string > ... > }; > > and then bind widgets to @name or @mime_type (and write the glue code > to hookup name, mime_type and parent to the model). What I'd really > like to do is more like: > > sheet my_sheet { > interface: > my_model : "serialized-model-string"; > }; > > and then bind widgets to @my_model.name or @my_model.mime_type. And > perhaps even change the model string when a button is pressed (e.g.: > make my_model = my_model.parent). Adam supports dictionaries and arrays. So you could do this as: my_model : {name: "", mime_type: "", parent: ""}; You can then refer to an element such as my_model.parent - although there is no binding to a piece of a cell like this (dependencies aren't tracked through the aggregate types). You can also refer to an element in a dictionary with the syntax my_model[@parent]. The advantage here is you can use an expression, my_model[pred ? @parent : @name]. Because you can only bind against a cell (not part of a value) you can split this out: sheet my_sheet { interface: parent: ""; // bind to these name: ""; mime_type: ""; output: my_model <== { name: name, mime_type: mime_type, parent: parent }; // use this as the result. } The image size example takes this approach. At some point I'd like to tackle how to embed a sheet in a sheet (an interesting dependency problem). This approach works pretty well though. Note that from C++ you can set cells in an Adam sheet to any regular type (see the docs on the regular type concept and there is a little blurb about using custom types with Adam in the language reference). By providing functions that generate and operate on your types you can extend Adam with whatever types you want. Sean > > Is this within the scope of Adam? It's not really important that > my_model be a string and something else, it could just as easily be a > special sheet (which my code can recognize and glue to a model > factory). > > Best regards, > Ralph > > > ------------------------------------------------------- > SF email is sponsored by - The IT Product Guide > Read honest & candid reviews on hundreds of IT Products from real > users. > Discover which products truly live up to the hype. Start reading now. > http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click > _______________________________________________ > Adobe-source-devel mailing list > Ado...@li... > https://lists.sourceforge.net/lists/listinfo/adobe-source-devel |