Opened 9 years ago

Closed 8 years ago

Last modified 8 years ago

#12314 closed enhancement (fixed)

[patch][ccla] MVC support for dijit based on dojo.Stateful

Reported by: rahul Owned by: Chris Mitchell
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.

Attachments (3)

images.zip (22.6 KB) - added by rahul 9 years ago.
Binary resources (images) used in demos included in the patch.
dojox.mvc.zip (112.5 KB) - added by rahul 8 years ago.
MVC support based on dojo.Stateful, with minor updates.
dojox-mvc.patch (106.2 KB) - added by rahul 8 years ago.
Various improvements; patch rooted at dojox trunk.

Download all attachments as: .zip

Change History (32)

Changed 9 years ago by rahul

Attachment: images.zip added

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

comment:1 Changed 9 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 9 years ago by Eugene Lazutkin

Type: defectenhancement

comment:3 Changed 9 years ago by rahul

Thanks for changing the ticket type, Eugene.

comment:4 Changed 9 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 9 years ago by Mark Wubben

Cc: Mark Wubben added

comment:6 Changed 9 years ago by ben hockey

Cc: ben hockey added

comment:7 Changed 9 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 9 years ago by Chris Mitchell

Keywords: 1.7-mobile added; MVC removed

comment:9 Changed 9 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 9 years ago by rahul

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

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

Milestone: tbd1.7

comment:12 Changed 9 years ago by rahul

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

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

comment:13 Changed 9 years ago by Chris Mitchell

Description: modified (diff)

comment:14 Changed 8 years ago by rahul

Ported the MVC support to a dojox.mvc project, based on prior discussions on the topic. This addresses some, but not all, feedback received 3-odd weeks back. Will respond in more detail on list when time permits.

For this patch / version, the following folks have also helped with the move to dojox.mvc and other tasks: Ed Chatelain and Akira Sudoh.

comment:15 Changed 8 years ago by bill

Component: DijitDojox
Owner: set to Adam Peller

comment:16 Changed 8 years ago by Chris Mitchell

Owner: changed from Adam Peller to Chris Mitchell

Changed 8 years ago by rahul

Attachment: dojox.mvc.zip added

MVC support based on dojo.Stateful, with minor updates.

comment:17 Changed 8 years ago by Chris Mitchell

(In [24670]) refs #12314 initial checkin of mvc data binding !strict

comment:18 Changed 8 years ago by Chris Mitchell

rahul, please go through all test files and convert spaces to tabs. next time, ensure that all files use tabs for spacing, and have consistent EOL chars. several files did not follow style guidelines and had to be fixed.

comment:19 Changed 8 years ago by Chris Mitchell

submit next patch as a .patch against trunk. thx

comment:20 Changed 8 years ago by rahul

Thanks, ack'ed whitespace issues in tests, will clean up in subsequent patch(es).

Could you also check in mvc.js in dojox/trunk? Didn't see that go through in r24670; its in the attached zip and needs to be checked in.

comment:21 Changed 8 years ago by Chris Mitchell

Resolution: fixed
Status: newclosed

(In [24672]) fixes #12314 cleaned up tabs. Happy cinco de Mayo ;) !strict

Changed 8 years ago by rahul

Attachment: dojox-mvc.patch added

Various improvements; patch rooted at dojox trunk.

comment:22 Changed 8 years ago by rahul

Resolution: fixed
Status: closedreopened

Attaching a patch with various improvements made to dojox.mvc over the last few days. Includes my changes and changes made by Ed Chatelain (for included mobile demos etc.).

Please apply before release tag, thanks in advance.

comment:23 Changed 8 years ago by Chris Mitchell

Resolution: fixed
Status: reopenedclosed

(In [24866]) fixes #12314 patches for mvc from rahul and ed !strict

comment:24 Changed 8 years ago by Chris Mitchell

(In [24895]) refs #12314 missed testcases for mvc updates

comment:25 Changed 8 years ago by Chris Mitchell

(In [25330]) refs #12314 #12433 cleaup demos and tests for mvc \!strict

comment:26 Changed 8 years ago by Chris Mitchell

(In [25331]) refs #12314 #12433 cleaup demos and tests for mvc \!strict

comment:27 Changed 8 years ago by ben hockey

(In [25413]) refs #12314 #12432 #12863 modifying dojox.mvc to make better use of AMD dependencies. !strict

comment:28 Changed 8 years ago by ben hockey

(In [25414]) refs #12314 #12432 #12863 removed unneeded 'exports' dep in dojox/mvc/Bind.js !strict

comment:29 Changed 8 years ago by Adam Peller

Component: DojoxDojoX MVC
Note: See TracTickets for help on using tickets.