<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Keeping it dry: Generating JavaScript models from Rails models</title>
	<atom:link href="http://blog.higher-order.net/2008/08/12/keeping-it-dry/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.higher-order.net/2008/08/12/keeping-it-dry/</link>
	<description>topics: functional programming, concurrency, web-development, REST, dynamic languages</description>
	<lastBuildDate>Sun, 04 Jul 2010 07:43:34 -0700</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: Recent Links Tagged With "mvc" - JabberTags</title>
		<link>http://blog.higher-order.net/2008/08/12/keeping-it-dry/comment-page-1/#comment-19</link>
		<dc:creator>Recent Links Tagged With "mvc" - JabberTags</dc:creator>
		<pubDate>Thu, 21 Aug 2008 18:30:27 +0000</pubDate>
		<guid isPermaLink="false">http://blog.higher-order.net/?p=62#comment-19</guid>
		<description>[...] public links &gt;&gt; mvc   Keeping it dry: Generating JavaScript models from Rails models Saved by derWolff on Thu 21-8-2008   A Practical Review of ASP.NET MVC Saved by sandstorm36 on Sat [...]</description>
		<content:encoded><![CDATA[<p>[...] public links &gt;&gt; mvc   Keeping it dry: Generating JavaScript models from Rails models Saved by derWolff on Thu 21-8-2008   A Practical Review of ASP.NET MVC Saved by sandstorm36 on Sat [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: admin</title>
		<link>http://blog.higher-order.net/2008/08/12/keeping-it-dry/comment-page-1/#comment-14</link>
		<dc:creator>admin</dc:creator>
		<pubDate>Wed, 13 Aug 2008 17:17:37 +0000</pubDate>
		<guid isPermaLink="false">http://blog.higher-order.net/?p=62#comment-14</guid>
		<description>Hi again, Ed. 

I like that you are attempting to mimick ActiveRecord::Base in JavaScript, it sounds interesting and useful; I&#039;ll have a look at your code at some point... ;-)

&#8220;&lt;i&gt;One final point about style - from your examples you seem to usually downcase everything except the last part of the class name&#133;&lt;/i&gt;&#8221;

My convention is certainly not universal. I try to follow these primary conventions for code that is written in what Douglas Crockford calls &quot;Pseudo classical&quot; style (i.e., how JavaScript is usually written):
&lt;ol&gt;
	&lt;li&gt;Package-objects are always lowercase (a package object is what is created by the namespace function).&lt;/li&gt;

	&lt;li&gt;Constructor functions and singleton objects start with upper case.&lt;/li&gt;

	&lt;li&gt;Utility functions are lowercase.&lt;/li&gt;

&lt;/ol&gt;



I haven&#039;t checked this, but I believe that Ext is actually consistent in its naming conventions: Ext is a singleton object (which lives in the global namespace) ✓ Ext.data plays the role of a package object so it is not capitalized ✓ Ext.data.Record is a constructor function ✓ 

I think the only other rule that governs this is: if the object/function consists of two words then each word is uppercase, e.g., ColorPalette.

&#8220;&lt;i&gt;Thanks for maintaining a great blog!&lt;/i&gt;&#8221;

Thanks for that comment! Great to get some interaction, so keep commenting ;-)

/Karl</description>
		<content:encoded><![CDATA[<p>Hi again, Ed. </p>
<p>I like that you are attempting to mimick ActiveRecord::Base in JavaScript, it sounds interesting and useful; I&#8217;ll have a look at your code at some point&#8230; <img src='http://blog.higher-order.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>&#8220;<i>One final point about style &#8211; from your examples you seem to usually downcase everything except the last part of the class name&#0133;</i>&#8221;</p>
<p>My convention is certainly not universal. I try to follow these primary conventions for code that is written in what Douglas Crockford calls &#8220;Pseudo classical&#8221; style (i.e., how JavaScript is usually written):</p>
<ol>
<li>Package-objects are always lowercase (a package object is what is created by the namespace function).</li>
<li>Constructor functions and singleton objects start with upper case.</li>
<li>Utility functions are lowercase.</li>
</ol>
<p>I haven&#8217;t checked this, but I believe that Ext is actually consistent in its naming conventions: Ext is a singleton object (which lives in the global namespace) ✓ Ext.data plays the role of a package object so it is not capitalized ✓ Ext.data.Record is a constructor function ✓ </p>
<p>I think the only other rule that governs this is: if the object/function consists of two words then each word is uppercase, e.g., ColorPalette.</p>
<p>&#8220;<i>Thanks for maintaining a great blog!</i>&#8221;</p>
<p>Thanks for that comment! Great to get some interaction, so keep commenting <img src='http://blog.higher-order.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>/Karl</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ed Spencer</title>
		<link>http://blog.higher-order.net/2008/08/12/keeping-it-dry/comment-page-1/#comment-13</link>
		<dc:creator>Ed Spencer</dc:creator>
		<pubDate>Wed, 13 Aug 2008 16:02:13 +0000</pubDate>
		<guid isPermaLink="false">http://blog.higher-order.net/?p=62#comment-13</guid>
		<description>Hi Karl,

Thanks for that.  MVC.model.Base is somewhat akin to ActiveRecord::Base - you just tell it what your model is called and what fields to include and from that it knows how to map each model to a URL resource, how to pluralize/inflect (in most instances anyway), as well as providing convenient Stores for both an individual model (e.g. /my_resource/1.json) or a collection (/my_resource.json).

Model was one of the first classes I wrote and is in need of some major refactoring - I&#039;m just trying to figure out the best way at the moment.  I like the approach you take in your post about extending Ext.data.Record - I think I&#039;ll give it a go that way.  I&#039;m really trying to achieve a Rails-like model definition so I&#039;ll see how far that goes...

The code is on Github at http://github.com/edspencer/ext-mvc/tree/master/model/base.js if you&#039;re interested.  Model.Base is not pretty (yet) but some of the other bits are!

One final point about style - from your examples you seem to usually downcase everything except the last part of the class name (e.g. com.trifork.tribook.model.Reservation).  ExtJs seems to be quite random though - e.g. Ext.data.Record, Ext.form.Action.Load, Ext.ColorPalette all seem to follow a different convention.  &#039;Ext&#039; is always capitalized, the next segment is usually not (except for some classes like Ext.Ajax and Ext.ColorPalette), then the third segment is usually capitalized again.  Do you know of a &#039;universal&#039; convention for this?  Why not just capitalize everything?

Thanks for maintaining a great blog!

Ed</description>
		<content:encoded><![CDATA[<p>Hi Karl,</p>
<p>Thanks for that.  MVC.model.Base is somewhat akin to ActiveRecord::Base &#8211; you just tell it what your model is called and what fields to include and from that it knows how to map each model to a URL resource, how to pluralize/inflect (in most instances anyway), as well as providing convenient Stores for both an individual model (e.g. /my_resource/1.json) or a collection (/my_resource.json).</p>
<p>Model was one of the first classes I wrote and is in need of some major refactoring &#8211; I&#8217;m just trying to figure out the best way at the moment.  I like the approach you take in your post about extending Ext.data.Record &#8211; I think I&#8217;ll give it a go that way.  I&#8217;m really trying to achieve a Rails-like model definition so I&#8217;ll see how far that goes&#8230;</p>
<p>The code is on Github at <a href="http://github.com/edspencer/ext-mvc/tree/master/model/base.js" rel="nofollow">http://github.com/edspencer/ext-mvc/tree/master/model/base.js</a> if you&#8217;re interested.  Model.Base is not pretty (yet) but some of the other bits are!</p>
<p>One final point about style &#8211; from your examples you seem to usually downcase everything except the last part of the class name (e.g. com.trifork.tribook.model.Reservation).  ExtJs seems to be quite random though &#8211; e.g. Ext.data.Record, Ext.form.Action.Load, Ext.ColorPalette all seem to follow a different convention.  &#8216;Ext&#8217; is always capitalized, the next segment is usually not (except for some classes like Ext.Ajax and Ext.ColorPalette), then the third segment is usually capitalized again.  Do you know of a &#8216;universal&#8217; convention for this?  Why not just capitalize everything?</p>
<p>Thanks for maintaining a great blog!</p>
<p>Ed</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: krukow</title>
		<link>http://blog.higher-order.net/2008/08/12/keeping-it-dry/comment-page-1/#comment-12</link>
		<dc:creator>krukow</dc:creator>
		<pubDate>Wed, 13 Aug 2008 12:14:32 +0000</pubDate>
		<guid isPermaLink="false">http://blog.higher-order.net/?p=62#comment-12</guid>
		<description>Hello Ed,

Ah, yes I see the problem. I&#039;m not sure how your MVC.model.Base works; however, if you were just using regular models (i.e. models created by Ext.Record.create), then I think you could get around this using inheritance.

The strategy could be: code-generate the base model using the approach above (or your own adapted version), then create a model which extends the base. If you put all your extra logic in the extended class then you can safely regenerate the base class when your migration changes -- the base would be overridden, but the extending model would remain the same.

Incidentally, you could use the code I posted on extending models created by Ext.Record.create in &lt;a href=&quot;http://blog.higher-order.net/2008/03/18/extending-extdatarecord-to-support-inheritance-for-domain-types/&quot; rel=&quot;nofollow&quot;&gt;this blog posting&lt;/a&gt;.

Think that would work out for you?

/Karl</description>
		<content:encoded><![CDATA[<p>Hello Ed,</p>
<p>Ah, yes I see the problem. I&#8217;m not sure how your MVC.model.Base works; however, if you were just using regular models (i.e. models created by Ext.Record.create), then I think you could get around this using inheritance.</p>
<p>The strategy could be: code-generate the base model using the approach above (or your own adapted version), then create a model which extends the base. If you put all your extra logic in the extended class then you can safely regenerate the base class when your migration changes &#8212; the base would be overridden, but the extending model would remain the same.</p>
<p>Incidentally, you could use the code I posted on extending models created by Ext.Record.create in <a href="http://blog.higher-order.net/2008/03/18/extending-extdatarecord-to-support-inheritance-for-domain-types/" rel="nofollow">this blog posting</a>.</p>
<p>Think that would work out for you?</p>
<p>/Karl</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ed Spencer</title>
		<link>http://blog.higher-order.net/2008/08/12/keeping-it-dry/comment-page-1/#comment-11</link>
		<dc:creator>Ed Spencer</dc:creator>
		<pubDate>Wed, 13 Aug 2008 11:33:20 +0000</pubDate>
		<guid isPermaLink="false">http://blog.higher-order.net/?p=62#comment-11</guid>
		<description>I&#039;ve had a similar idea in the past but found that you can&#039;t safely regenerate your JS models this way (or at least I can&#039;t) because the JS models often contain additional model logic.  I&#039;ve been creating an MVC framework on top of ExtJS for a few months and a typical model looks like this:


AdFunded.models.AdvertisingCategory = new Ext.ux.MVC.model.Base(&#039;advertising_category&#039;, {
  fields: [
    { name: &#039;id&#039;,          type: &#039;int&#039;},
    { name: &#039;name&#039;,        type: &#039;string&#039;},
    { name: &#039;description&#039;, type: &#039;string&#039;}
  ],
  controller_name:   &#039;AdvertisingCategoriesController&#039;,
  human_plural_name: &#039;Advertising Categories&#039;,
  url_name:          &#039;advertising_categories&#039;
});


There&#039;s a bit of magic going on under the covers here but essentially the model creates an Ext.data.Record with the fields you pass it in the background.  Trouble is - to regenerate this would lose the additional config options I&#039;ve given the model (and some models have much more inside them than this one).

To counter this I have been writing a Schema library for Ext MVC, which converts Rails migrations (or potentially any other kind) into a JS form and runs them in sequence at run time.  That would mean an end to specifying the fields in the model, which makes migration easier, but it&#039;s also nice to have them there in the model file (like with the rails annotated models plugin).

I&#039;m still not sure what the best way to go on that one is - any ideas?</description>
		<content:encoded><![CDATA[<p>I&#8217;ve had a similar idea in the past but found that you can&#8217;t safely regenerate your JS models this way (or at least I can&#8217;t) because the JS models often contain additional model logic.  I&#8217;ve been creating an MVC framework on top of ExtJS for a few months and a typical model looks like this:</p>
<p>AdFunded.models.AdvertisingCategory = new Ext.ux.MVC.model.Base(&#8216;advertising_category&#8217;, {<br />
  fields: [<br />
    { name: 'id',          type: 'int'},<br />
    { name: 'name',        type: 'string'},<br />
    { name: 'description', type: 'string'}<br />
  ],<br />
  controller_name:   &#8216;AdvertisingCategoriesController&#8217;,<br />
  human_plural_name: &#8216;Advertising Categories&#8217;,<br />
  url_name:          &#8216;advertising_categories&#8217;<br />
});</p>
<p>There&#8217;s a bit of magic going on under the covers here but essentially the model creates an Ext.data.Record with the fields you pass it in the background.  Trouble is &#8211; to regenerate this would lose the additional config options I&#8217;ve given the model (and some models have much more inside them than this one).</p>
<p>To counter this I have been writing a Schema library for Ext MVC, which converts Rails migrations (or potentially any other kind) into a JS form and runs them in sequence at run time.  That would mean an end to specifying the fields in the model, which makes migration easier, but it&#8217;s also nice to have them there in the model file (like with the rails annotated models plugin).</p>
<p>I&#8217;m still not sure what the best way to go on that one is &#8211; any ideas?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
