Opened 11 years ago

Last modified 11 years ago

#12314 closed enhancement

[patch][ccla] MVC support for dijit based on dojo.Stateful — at Version 13

Reported by: rahul Owned by:
Priority: high Milestone: 1.7
Component: DojoX MVC Version: 1.6.0b1
Keywords: 1.7-mobile Cc: Mark Wubben, ben hockey
Blocked By: Blocking:

Description (last modified by Chris Mitchell)

As background, we discussed MVC (Model-View-Controller) enhancements to Dojo late last year on the contributors list and also presented it to a few folks at DDD in October.

http://chrism.dojotoolkit.org/dojomvc/

We now have the code ready to propose this addition for dijit (patches forthcoming).

Most of the base MVC functionality is provided by two new classes:

  • dijit.StatefulModel - The JavaScript model on the client, takes plain JavaScript object input.
  • dijit._DataBindingMixin - The mixin that enables dijits to have the declarative data binding specification capability ("ref" attribute or data-dojo-props property).

The class docs in the patch have lot more details.

Then there are three new MVC container widgets (plus a base class) building on base functionality above as follows:

  • dijit.mvc._Container - Base class for most MVC containers.
  • dijit.mvc.Group - Container that enables data binds for hierarchical data.
  • dijit.mvc.Repeat - Container that enables data binds for repeating data i.e. arrays.
  • dijit.mvc.Generate - Container that generates its view based on data its bound to.

The two small changes to existing files are to ensure that those dijits consult model or bind validity before determining the response to isValid().

In addition, there are a number of demos in the tests/ directory, corresponding new doh and robot tests along with an index page for demos and some new demo resources (stylesheets, images, json files).

It seemed best to get the patch out now, though the following incremental updates are planned over the next week or two:

  • dojo.store support - Loading model input from stores and commiting model changes.
  • dojo.Stateful-ness of dijit._DataBindingMixin - The API needs to be better aligned with dojo.Stateful i.e. get("binding") instead of getBinding() etc.
  • Duplication in dijit.mvc._Container - Two private methods are copied for dijit._Templated, there may be a way to avoid that with some more thought.
  • <script>s in demo html files instantiating the model currently assume synch for simplicity.

The original authors of this body of work are Rahul Akolkar (me) and Charlie Wiecha. We have been joined by Ed Chatelain this year (the tests come from Ed, for example). This patch is covered by the IBM CCLA. We also showed this work to Bill and Doug last week and have incorporated some of their initial feedback into the patch.

As always, feedback is much appreciated.

Change History (14)

Changed 11 years ago by rahul

Attachment: images.zip added

Binary resources (images) used in demos included in the patch.

comment:1 Changed 11 years ago by rahul

This ticket should have been an enhancement clearly, but I don't see an option to change it now (from a defect).

comment:2 Changed 11 years ago by Eugene Lazutkin

Type: defectenhancement

comment:3 Changed 11 years ago by rahul

Thanks for changing the ticket type, Eugene.

comment:4 Changed 11 years ago by rahul

I've updated the main patch containing the MVC functionality to include most changes mentioned towards the bottom of the original issue description and some other improvements:

  • Added dojo.store support: models can be populated from stores and have commit/reset function.
  • The dijit._DataBindingMixin class is now aligned with the dojo.Stateful affinity of the rest of this work.
  • There are now some examples that show async loading from stores as well.
  • Couple of new tests, an MVC tests runner, numerous code style and miscellaneous improvements.

At this point, I'd consider this patch ready. Feedback welcome.

comment:5 Changed 11 years ago by Mark Wubben

Cc: Mark Wubben added

comment:6 Changed 11 years ago by ben hockey

Cc: ben hockey added

comment:7 Changed 11 years ago by rahul

I've updated the patch to incorporate most feedback from this thread on the contributors list:

http://thread.gmane.org/gmane.comp.web.dojo.devel/13865

Next up, I intend to look at changes for programmatic dijit instantiations.

comment:8 Changed 11 years ago by Chris Mitchell

Keywords: 1.7-mobile added; MVC removed

comment:9 Changed 11 years ago by rahul

The latest patch incorporates most feedback from before-mentioned thread on contributors list. I think the code is ready for another look. Thanks in advance for the feedback :-)

comment:10 Changed 11 years ago by rahul

With this patch update, I'm done with my changes for now.

comment:11 Changed 11 years ago by Kenneth G. Franqueiro

Milestone: tbd1.7

comment:12 Changed 11 years ago by rahul

trunk + latest patch hosted here (thanks chrism for hosting!):

http://chrism.dojotoolkit.org/dojomvc/

comment:13 Changed 11 years ago by Chris Mitchell

Description: modified (diff)
Note: See TracTickets for help on using tickets.