Search This Blog

Tuesday, July 15, 2014

MVC in Polymer.Dart

I have seen a couple of different implementations of the MVC model in Polymer.Dart.

I redid the codelab example adding indexedDB support.  I followed the count-down example given on the Dart sample code page.  The MVC model is implemented with a model and a view model.

The basic class structure and how to write objects to memory are included in the model.  The model is extended by the view model.  The "view" model integrates managing the indexedDB and managing the objects in memory.

Example the addCodelab code:
void addCodelab(Codelab codelab){
//validate codelab
_store.add(codelab).then((_){
hasCodelabs = notifyPropertyChange(const Symbol('hasCodelabs'),
hasCodelabs, (codelabs.length == 0) ? false: true);
},
onError: (e) {print('duplicate key'); });
}
The polymer element then controls the firing of functions and life cycle functions (initialization, placed in the DOM, and being removed from the DOM).  The different lifecycle functions lead to interesting questions about using a bind if template or a plain if template and how that effects the call of attached functions.

Another remaining question is where to put the validation.  The current validation is in the polymer element.  It seems prudent to place validation in the either the view controller or in the model.

No comments:

Post a Comment