<div dir="ltr"><br><br><div class="gmail_quote">On Wed, Jun 23, 2010 at 9:01 PM, Alberto G. Corona <span dir="ltr">&lt;<a href="mailto:agocorona@gmail.com">agocorona@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br>I forgot to send this to the list. This answers also some questions about the idea of server page control. I don´t think in to eliminate the option of client code, not at all. but server control is neccesary to ease interactions that MUST use data in the server. <div>

<br></div><div>In fact, as I suggest here, pottentially, HJScript can be extended to make it run in the server or in the client depending on the requirements, just modifying (i guess) the underlying monad,  because it has many of the common functionalities needed.<div>
<div></div><div class="h5"><br>
<div class="gmail_quote"><br>Hi michael,<div>More or less to solve these concrete problems is a requirement. I think neither using comunications  using algebraic data types, nor JSON neither HTML downloading of pierces. My idea is just to  send javascript sentences from server to client, and then evaluate ( with javascript &quot;eval&quot;) them in the client. </div>


<div><br></div><div>Details below:<br><div><br><div class="gmail_quote"><div>2010/6/22 Michael Snoyman <span dir="ltr">&lt;<a href="mailto:michael@snoyman.com" target="_blank">michael@snoyman.com</a>&gt;</span><br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">I think it would be useful if we spoke in more concrete terms: in particular, let&#39;s figure out some real world problems we want to solve, instead of designing the perfect technology. I&#39;ll start with some simple problems, feel free to add some of your own:<div>

<div>

<br></div><div>1) Form validation. Here&#39;s an example from a project I&#39;m working on now: disable field B if field A has one of a list of values. We clearly need to ensure server-side that field B has no value set if the conditions for A are fulfilled, but we&#39;d like to &quot;gray out&quot; the field client side.</div>



<div><br></div></div></div></blockquote><div>because I have a copy of the HTML tree in the server( the way to maintain synchronization trough event forwarding to the server is not described here) I can check te value of the field A. If A meets the condition I just send to the browser the HTML DOM sentence</div>


<div><br></div><div>&quot;form.B.style.active=Disabled&quot; </div><div><br></div><div>(This is javascript pseudocode the real sentence look similar, but I don´t care now to check the documentation and look for the details)</div>


<div><br></div><div>in the browser the execution of </div><div><br></div><div>eval(&quot;form.B.style.active=Disabled&quot; )</div><div><br></div><div>will disable the field. </div><div><br></div><div>If we develop a  XML DOM library that generate javascript strings, then the haskell code in the server would map 1:1 with the javascript code.For the javascript developer will be muchi like developing javascript in the client. In fact the code would share ,much ideas and code with HJScript because HJScript does also generate javascript strings. I think that  we can extend HJSCript to make it run either in the server or the client, depending on the choices. HJScript uses HTML DOM.</div>


<div><br></div><div>This case does a lot less sense if the control code does not make use of data in the server. For example, if the list of values of a combo box depends on the choice or values in another field in the form.</div>

<div>
<div> </div></div></div></div></div></div></div></div></div></blockquote><div>I understand the motivation here, but my biggest concern with this type of approach is that it seems very unRESTful. I&#39;m not a REST idealogue, but planning to design a complex system that attempts to keep two identical copies of browser state over a stateless protocol just doesn&#39;t seem possible. I&#39;m also concerned about Jeremy&#39;s comments regarding bandwidth usage and latency.</div>
<div><br></div><div>The approach I would take is to accept the fact that we&#39;re going to have to write code twice. But instead of writing a full-blown Haskell application, and then converting all of that code to Javascript, let&#39;s build small components that encapsulate the same functionality in Haskell and Javascript (the idea behind widgets). If we do it properly, we can easily combine these components together, and produce applications where the Javascript mirrors the Haskell properly, assuming the individual components are written correctly.</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div><div><div class="h5"><div class="gmail_quote"><div><div><div class="gmail_quote"><div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><div></div><div>2) Ajax loading of pieces of pages. We can obviously make this very simple (&quot;download some HTML from this URL and stick it in this div&quot;) or much more complex (&quot;serialize this Haskell data structure to JSON, transfer it, parse it client side and build up the DOM tree&quot;).</div>



<div><br></div></div></blockquote></div><div>Just forward  and eval the string </div><div><br></div><div>&quot;divName.innerHTML=\&quot;text of th HTML to include\&quot;&quot; </div><div><div> </div></div></div></div></div>
</div></div></div></div></blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div><div><div class="h5"><div class="gmail_quote"><div><div><div class="gmail_quote">
<div><div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div dir="ltr"><div></div><div>3) Perhaps not what you were thinking about, but easy integration with Javascript widgets. Here&#39;s an example: a photo gallery that has forward-next buttons. When Javascript is disabled, the server generates a new HTML page for each request. With Javascript enabled, it uses something like jquerytools.</div>



<div><br></div></div></blockquote></div><div>This requires the detection of this condition. At the beginning, if the jscript code deoes not respond, ttoug the Ajax channel, then use HTML navigation. </div></div></div></div>
</div></div></div></div></blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div><div><div class="h5"><div class="gmail_quote"><div><div><div class="gmail_quote">
<div><div><div> </div></div></div></div></div></div></div></div></div></div></blockquote><div>Actually, it should work the opposite way, through graceful degradation. We send a webpage that operates perfectly with HTML alone, and link in a Javascript file that adds extra functionality.</div>
</div></div>