r96451 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96450‎ | r96451 | r96452 >
Date:17:09, 7 September 2011
Author:tparscal
Status:deferred
Tags:
Comment:
Added basic view test.
Modified paths:
  • /trunk/parsers/wikidom/lib/synth/bases/es.ModelContainerItem.js (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/bases/es.ViewContainer.js (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/bases/es.ViewContainerItem.js (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/models/es.BlockModel.js (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/models/es.CommentBlockModel.js (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/models/es.ParagraphBlockModel.js (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/models/es.TableBlockModel.js (modified) (history)
  • /trunk/parsers/wikidom/lib/synth/views/es.DocumentView.js (modified) (history)
  • /trunk/parsers/wikidom/tests/synth/index.html (modified) (history)
  • /trunk/parsers/wikidom/tests/synth/test.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/tests/synth/index.html
@@ -14,6 +14,8 @@
1515 <script src="../../lib/synth/bases/es.EventEmitter.js"></script>
1616 <script src="../../lib/synth/bases/es.ModelContainer.js"></script>
1717 <script src="../../lib/synth/bases/es.ModelContainerItem.js"></script>
 18+ <script src="../../lib/synth/bases/es.ViewContainer.js"></script>
 19+ <script src="../../lib/synth/bases/es.ViewContainerItem.js"></script>
1820 <script src="../../lib/synth/bases/es.AggregateArray.js"></script>
1921 <script src="../../lib/synth/es.Range.js"></script>
2022 <script src="../../lib/jquery.js"></script>
Index: trunk/parsers/wikidom/tests/synth/test.js
@@ -157,6 +157,25 @@
158158 // TODO: Events for appending, prepending, inserting and removing
159159 } );
160160
 161+
 162+test( 'es.ViewContainer', function() {
 163+ var modelContainer = new es.ModelContainer(),
 164+ modelItem1 = new es.ModelContainerItem(),
 165+ modelItem2 = new es.ModelContainerItem(),
 166+ modelItem3 = new es.ModelContainerItem();
 167+ var viewContainer = new es.ViewContainer( modelContainer );
 168+ viewContainer.createItemView = function( itemModel ) {
 169+ return new es.ViewContainerItem( itemModel );
 170+ };
 171+
 172+ //
 173+ modelContainer.append( modelItem1 );
 174+ modelContainer.append( modelItem2 );
 175+ modelContainer.append( modelItem2 );
 176+
 177+ equals( viewContainer.views, 3, 'es.ViewContainer' );
 178+} );
 179+
161180 function ContentStub( name, size ) {
162181 this.name = name;
163182 this.size = size;
Index: trunk/parsers/wikidom/lib/synth/models/es.BlockModel.js
@@ -45,6 +45,13 @@
4646 /* Methods */
4747
4848 /**
 49+ * Creates a view for this model
 50+ */
 51+es.BlockModel.prototype.createView = function() {
 52+ return new es.BlockView( this );
 53+};
 54+
 55+/**
4956 * Checks for a trait.
5057 *
5158 * Traits are boolean flags that indicate supported behavior
Index: trunk/parsers/wikidom/lib/synth/models/es.CommentBlockModel.js
@@ -27,6 +27,13 @@
2828 /* Methods */
2929
3030 /**
 31+ * Creates a view for this model
 32+ */
 33+es.BlockModel.prototype.createView = function() {
 34+ return new es.BlockView( this );
 35+};
 36+
 37+/**
3138 * Gets the length of all content.
3239 *
3340 * @method
Index: trunk/parsers/wikidom/lib/synth/models/es.ParagraphBlockModel.js
@@ -27,6 +27,13 @@
2828 /* Methods */
2929
3030 /**
 31+ * Creates a view for this model
 32+ */
 33+es.ParagraphBlockModel.prototype.createView = function() {
 34+ return new es.ParagraphBlockView( this );
 35+};
 36+
 37+/**
3138 * Gets the length of all content.
3239 *
3340 * @method
Index: trunk/parsers/wikidom/lib/synth/models/es.TableBlockModel.js
@@ -37,6 +37,13 @@
3838 /* Methods */
3939
4040 /**
 41+ * Creates a view for this model
 42+ */
 43+es.TableBlockModel.prototype.createView = function() {
 44+ return new es.TableBlockView( this );
 45+};
 46+
 47+/**
4148 * Gets the length of all content.
4249 *
4350 * @method
Index: trunk/parsers/wikidom/lib/synth/bases/es.ModelContainerItem.js
@@ -23,6 +23,13 @@
2424 };
2525
2626 /**
 27+ * Creates a view for this model
 28+ */
 29+es.ModelContainerItem.prototype.createView = function() {
 30+ return new es.ViewContainerItem( this );
 31+};
 32+
 33+/**
2734 * Attaches item to a container.
2835 *
2936 * @method
Index: trunk/parsers/wikidom/lib/synth/bases/es.ViewContainerItem.js
@@ -11,6 +11,9 @@
1212 es.ViewContainerItem = function( model, typeName, tagName ) {
1313 es.EventEmitter.call( this );
1414 this.model = model;
 15+ if ( typeof typeName !== 'string' ) {
 16+ typeName = 'viewContainerItem';
 17+ }
1518 if ( typeof tagName !== 'string' ) {
1619 tagName = 'div';
1720 }
Index: trunk/parsers/wikidom/lib/synth/bases/es.ViewContainer.js
@@ -17,6 +17,9 @@
1818 es.EventEmitter.call( this );
1919 this.containerModel = containerModel;
2020 this.views = [];
 21+ if ( typeof typeName !== 'string' ) {
 22+ typeName = 'viewContainer';
 23+ }
2124 if ( typeof tagName !== 'string' ) {
2225 tagName = 'div';
2326 }
@@ -25,14 +28,14 @@
2629 .data( typeName, this );
2730 var container = this;
2831 this.containerModel.on( 'prepend', function( itemModel ) {
29 - var itemView = container.createItem( itemModel );
 32+ var itemView = container.createItemView( itemModel );
3033 container.views.unshift( itemView );
3134 container.$.prepend( itemView.$ );
3235 container.emit( 'prepend', itemView );
3336 container.emit( 'update' );
3437 } );
3538 this.containerModel.on( 'append', function( itemModel ) {
36 - var itemView = container.createItem( itemModel );
 39+ var itemView = container.createItemView( itemModel );
3740 container.views.push( itemView );
3841 container.$.append( itemView.$ );
3942 container.emit( 'append', itemView );
@@ -83,7 +86,7 @@
8487 };
8588
8689 es.ViewContainer.prototype.createItemView = function( itemModel ) {
87 - throw 'es.ViewContainer.createItem not implemented in this subclass';
 90+ throw 'es.ViewContainer.createItemView not implemented in this subclass';
8891 };
8992
9093 /* Inheritance */
Index: trunk/parsers/wikidom/lib/synth/views/es.DocumentView.js
@@ -1,7 +1,11 @@
2 -es.DocumentView = function( blockViews ) {
3 - es.DomContainer.call( this, 'blocks' );
 2+es.DocumentView = function( documentModel ) {
 3+ es.ViewContainer.call( this, documentModel, 'blocks' );
44 };
55
 6+es.DocumentView.prototype.createItemView = function( itemModel ) {
 7+ return itemModel.createView();
 8+};
 9+
610 /* Inheritance */
711
8 -es.extend( es.DocumentView, es.DomContainer );
 12+es.extend( es.DocumentView, es.ViewContainer );

Status & tagging log