<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
	<title>jQuery Grid Plugin - jqGrid - Topic: Namespace pollution</title>
	<link>http://www.trirand.com/blog/?page_id=393/discussion/namespace-pollution</link>
	<description><![CDATA[Grid plugin]]></description>
	<generator>Simple:Press Version 5.7.5.3</generator>
	<atom:link href="http://www.trirand.com/blog/?page_id=393/discussion/namespace-pollution/rss" rel="self" type="application/rss+xml" />
        <item>
        	<title>markw65 on Namespace pollution</title>
        	<link>http://www.trirand.com/blog/?page_id=393/discussion/namespace-pollution#p9159</link>
        	<category>Discussion</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/discussion/namespace-pollution#p9159</guid>
        	        	<description><![CDATA[<p>Hi Tony,</p>
</p>
<p>I understand.</p>
</p>
<p>To make things a little easier (and to help with the step-by-step), I&#39;ve simplified things a little. I&#39;ve just checked in a new version in my fork of the grid. There are now two branches. "master" and "newapi".</p>
</p>
<p>On the master branch, I&#39;ve added a function $.jgrid.extend() which extends both $.fn and $.fn.jqGrid with its argument. I&#39;ve also changed every call to $.fn.extend into a call to $.jgrid.extend, and also modified $.fn.jqGrid to handle string arguments as before.</p>
</p>
<p>The upshot is that there&#39;s only a small number of changes, but it supports the new calling convention ( .jqGrid("method",args) rather than .method(args)). But it doesnt allow you to turn off the "old" calling convention (because the grid itself still uses that).</p>
</p>
<p>Then, on the "newapi" branch, I&#39;ve also changed all the call sites to those functions to use the new calling convention. Obviously, a lot more changes, and much harder to verify.</p>
</p>
<p>Im hoping you can pull in the master changes before too long. Once those are in, I should be able to keep the newapi branch up to date fairly easily (I have a script to convert between the two calling conventions).</p>
</p>
<p>Hopefully, in the long run, you&#39;ll take the newapi changes too - but I can see that thats going to be harder.</p>
</p>
<p>Mark</p>
]]></description>
        	        	<pubDate>Mon, 31 Aug 2009 22:51:17 +0300</pubDate>
        </item>
        <item>
        	<title>tony on Namespace pollution</title>
        	<link>http://www.trirand.com/blog/?page_id=393/discussion/namespace-pollution#p9063</link>
        	<category>Discussion</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/discussion/namespace-pollution#p9063</guid>
        	        	<description><![CDATA[<p>Hello Mark,</p>
<p>Thanks. I see the code in GitHub. Also I plan to implement this, but need to make it step by step - need to test it.</p>
<p>Thanks</p>
<p>Best Regards</p>
<p>Tony</p>
]]></description>
        	        	<pubDate>Sun, 30 Aug 2009 12:00:20 +0300</pubDate>
        </item>
        <item>
        	<title>markw65 on Namespace pollution</title>
        	<link>http://www.trirand.com/blog/?page_id=393/discussion/namespace-pollution#p8901</link>
        	<category>Discussion</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/discussion/namespace-pollution#p8901</guid>
        	        	<description><![CDATA[<p>No - you express yourself very clearly. Apparently I dont <img class="spSmiley" style="margin:0" title="Laugh" src="/blog/wp-content/forum-smileys/sf-laugh.gif" alt="Laugh" /></p>
</p>
<p>If you look at my changes (better yet, try them out), you will see that existing code works *without any modification*.</p>
</p>
<p>In addition, you can use the new syntax ( $(selector).jqGrid("method",args) rather than $(selector).method(args) ). But its not required.</p>
</p>
<p>The only time users need to make a change is if they want to get rid of the old syntax, in order to prevent the existing namespace pollution.</p>
</p>
<p>In that case, they set $.jgrid.no_legacy_api=true, and then they *only* get the new syntax.</p>
</p>
<p>So once again - there is /no/ breakage of existing code with these changes.</p>
</p>
<p>And yes - of course there are many more functions that should be fixed - I just targetted grid.base.js to show you where I was going, and to see what you thought.</p>
</p>
<p>Mark</p>
]]></description>
        	        	<pubDate>Fri, 21 Aug 2009 08:45:28 +0300</pubDate>
        </item>
        <item>
        	<title>tony on Namespace pollution</title>
        	<link>http://www.trirand.com/blog/?page_id=393/discussion/namespace-pollution#p8859</link>
        	<category>Discussion</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/discussion/namespace-pollution#p8859</guid>
        	        	<description><![CDATA[<p>Hello Mark,</p>
<p>It seems that I do not express myself clear. What I want is that the existing users should not change the existing code and this is definitley done with your script.</p>
<p>I need to do some tests. Also there are other methods whch maybe should be included - in custom module and in user contributed modules.</p>
<p>Thanks again for you work. Will let you know what is my finall decision.</p>
<p>Best Regards</p>
<p>Tony</p>
]]></description>
        	        	<pubDate>Fri, 21 Aug 2009 02:03:04 +0300</pubDate>
        </item>
        <item>
        	<title>markw65 on Namespace pollution</title>
        	<link>http://www.trirand.com/blog/?page_id=393/discussion/namespace-pollution#p8806</link>
        	<category>Discussion</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/discussion/namespace-pollution#p8806</guid>
        	        	<description><![CDATA[<p>Hi Tony,</p>
</p>
<p>Yes - my solution doesnt (shouldnt!) break anything - unless the user explicitly asks for the old api to be removed.</p>
</p>
<p>I&#39;ve modified 3.5.2, and put it at <a href="http://myosotissp.com/jqGrid-3.5.2x.tgz" rel="nofollow" target="_blank">http://myosotissp.com/jqGrid-3.5.2x.tgz</a> to show you exactly what Im thinking.</p>
</p>
<p>For this, Ive only moved the methods defined in grid.base.js, but I&#39;ve rewritten all calls to those methods (from anywhere) to use the "new" syntax.</p>
</p>
<p>If you use this as a straight replacement for 3.5.2, any existing code should continue to work (mine does!). In addition you can write calls to any method defined in grid.base.js using the new syntax, eg:</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; var row = grid.jqGrid("getRowData",rowid);</p>
<p>However, if you also set $.jgrid.no_legacy_api=true prior to loading grid.base.js, then /only/ the new syntax is supported (and so none of those names appear in $.fn - which is what Im really after).</p>
</p>
<p>Executive summary:</p>
<p>&#160;- no breakage of existing code (unless you want it).</p>
<p>&#160;- new syntax for calling the grid methods (I&#39;ve started to like this, because it makes it very easy to spot the calls to grid methods in my code).&#160;</p>
<p>&#160;- optionally remove all the clutter from $.fn (requires switching calling code to the new api).</p>
</p>
<p>Mark</p>
]]></description>
        	        	<pubDate>Wed, 19 Aug 2009 08:49:48 +0300</pubDate>
        </item>
        <item>
        	<title>tony on Namespace pollution</title>
        	<link>http://www.trirand.com/blog/?page_id=393/discussion/namespace-pollution#p8774</link>
        	<category>Discussion</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/discussion/namespace-pollution#p8774</guid>
        	        	<description><![CDATA[<p>Hello Mark,</p>
<p>Thanks for this - Yes I think we can make the grid better. Simple yes, I&#39;m interested, but this should not destroy the old funcionaliy.</p>
<p>Best Regards</p>
<p>Tony</p>
]]></description>
        	        	<pubDate>Wed, 19 Aug 2009 05:08:36 +0300</pubDate>
        </item>
        <item>
        	<title>markw65 on Namespace pollution</title>
        	<link>http://www.trirand.com/blog/?page_id=393/discussion/namespace-pollution#p8752</link>
        	<category>Discussion</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/discussion/namespace-pollution#p8752</guid>
        	        	<description><![CDATA[<p>Hi Tony,</p>
</p>
<p>Thanks for the feedback. Sorry to be so slow to respond &#8211; I didnt notice your post until now.</p>
</p>
<p>I&#39;ve just looked at the changes, and as you say, its an improvement, but there&#39;s still a lot of names added to both $ and $.fn.</p>
</p>
<p>I realized my proposed solution &#8211; to extend $.fn.jqGrid rather than $.fn &#8211; doesnt quite work (after trying it out on one of the methods!), because when you call $(selection).jqGrid.showCol() (for example), showCol gets called, but with the wrong &#8220;this&#8221; parameter (the jqGrid object, rather than the jQuery object).</p>
</p>
<p>It looks like the &#8220;standard&#8221; way to do this in jQuery UI is to instead do something like $(selection).jqGrid(&#8221;showCol&#8221;).</p>
</p>
<p>I think we could achieve this by following the approach I outlined in my original post, and modifying $.fn.jqGrid to do something like:</p>
<p>if (typeof p == &#8220;string&#8221;) {</p>
<p>&#160;&#160; var fn = $.fn.jqGrid[p];</p>
<p>&#160;&#160; if (fn) {</p>
<p>&#160;&#160;&#160;&#160; var args = $.makeArray(arguments).slice(1);</p>
<p>&#160;&#160;&#160;&#160; fn.call(this,args);</p>
<p>&#160; } else {</p>
<p>&#160;&#160; // error handling</p>
<p>&#160; }</p>
<p>&#160;&#160; return;</p>
<p>}</p>
</p>
<p>That way, any of the current $.fn.func could instead be called as $(selection).jqGrid(&#8221;func&#8221;, args). And as I said before, maintaining backward compatibility is trivial &#8211; the old interface would be available unless turned off by a flag.</p>
</p>
<p>I would be quite happy to make these changes &#8211; if you&#39;re interested in taking them? Given the amount of churn in jqGrid (which is good &#8211; it means things are improving!) maintaining these changes &#8220;externally&#8221; doesnt seem like an option.</p>
</p>
<p>Mark</p>
]]></description>
        	        	<pubDate>Tue, 18 Aug 2009 11:31:48 +0300</pubDate>
        </item>
        <item>
        	<title>tony on Namespace pollution</title>
        	<link>http://www.trirand.com/blog/?page_id=393/discussion/namespace-pollution#p8221</link>
        	<category>Discussion</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/discussion/namespace-pollution#p8221</guid>
        	        	<description><![CDATA[<p>Hello Mark,</p>
<p>First of all I want to Thank you for the invaluable coments. It is a long story&#8230;</p>
<p>You are absolutley right. I could not find the right words, but I do not like the methods like  $.stringToDoc, $.parse, $.stripHtml .. to appear this way. During the last days before publishing the final release I search a way how this can be done without changing hard the code. Also I have moved these methods to jgrid namespace, not sure if this is the best solution, but&#8230;.</p>
<p>What I have do additionally is to move all grid methods at end of code and make a fn.extend. This way the loading of jqGrid instace is speeded up (since we do not load every time the methods when we call jqGrid).</p>
<p>Thank you very much again. Will make the code better and better for developers too.</p>
<p>Best Regards</p>
<p>Tony</p>
]]></description>
        	        	<pubDate>Tue, 04 Aug 2009 01:49:20 +0300</pubDate>
        </item>
        <item>
        	<title>markw65 on Namespace pollution</title>
        	<link>http://www.trirand.com/blog/?page_id=393/discussion/namespace-pollution#p8161</link>
        	<category>Discussion</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/discussion/namespace-pollution#p8161</guid>
        	        	<description><![CDATA[<p>Just started working with jqGrid, and so far, I really like it...</p>
<p>... at least, what it does... Im a little concerned with how it does it <img class="spSmiley" style="margin:0" title="Smile" src="/blog/wp-content/forum-smileys/sf-smile.gif" alt="Smile" /></p>
</p>
<p>Basically, Im rather concerned about the namespace pollution. It adds dozens (hundreds?) of names to the $ namespace, and lots more to the $.fn namespace. It even adds a number to the window object.</p>
</p>
<p>Many of these names are very ordinary - $.stringToDoc, $.parse, $.stripHtml just to list a few. I&#39;m fairly new to jQuery, so I&#39;ve not looked at too many other plugins, but if they all do the same, then using them together is likely to be a nightmare.</p>
</p>
<p>I realize that the api is now "out there" so you cant just drop it - but I&#39;d like to suggest a possible change to move to a cleaner setup.</p>
<p>If, instead of "$.fn.getGridParam = function...; $.fn.setGridParam = function..." etc, you wrote it as:</p>
</p>
<p>var methods = {</p>
<p>&#160;&#160;&#160; ....</p>
<p>&#160;&#160;&#160; getGridParam : function...,</p>
<p>&#160;&#160;&#160; setGridParam : function...</p>
<p>&#160;&#160;&#160; ....</p>
<p>}</p>
<p>if ($.jgrid.legacy_api) $.fn.extend(methods);</p>
<p>$.extend($.fn.jqGrid,methods);</p>
</p>
<p>Then you could have $.jgrid.legacy_api default to true for the next release (or forever, even) - but anyone who wanted to keep a minimal footprint could do so by setting it to false.</p>
<p>Similarly you could create a $.jqGrid which could hold the functions, rather than (or in addition to) attaching them directly to $.</p>
<p>And finally you could move the window.* functions into $.jqGrid.</p>
<p>Net result would be no breakage of existing code, but a much less intrusive plugin (for users who want it) moving forward.</p>
</p>
<p>Once again - I really like it, and Im almost certainly going to use it. Id just feel more comfortable if it didnt have such an impact on the namespace...</p>
</p>
<p>Mark</p>
]]></description>
        	        	<pubDate>Thu, 30 Jul 2009 17:31:53 +0300</pubDate>
        </item>
</channel>
</rss>