OT Adam D Ruppe's web stuff

Adam D. Ruppe destructionator at gmail.com
Tue Feb 7 12:00:25 PST 2012


On Tuesday, 7 February 2012 at 19:27:46 UTC, bls wrote:
> You know it, web stuff documentation is a weak point.

Yeah, I know.

> looks very interesting ...  so a real world sample app would be 
> nice..

The closest i have is a little blog like thing that I started
and haven't worked on since.

http://arsdnet.net/blog/my-source

> I would like to see a sample RIA -  M- V-C  wise, using (say 
> using dojo dijit as View layer ) in conjunction with the D web 
> stuff . (Model- Controler)

I haven't used one of those toolkits, but plain javascript
is easy to do like this.


I'm writing a little browser game on the weekends. When I finish
it, I might be able to show it to you. (I'll have to replace the
copyrighted images in there right now though.)



Basically you just call the server functions in your event 
handlers.


Want to replace a div with content from the other side?

D
===
import arsd.web;
class Server : ApiProvider {
   string hello(string name) { return "hello " ~ name; }
}
mixin FancyMain!Server;
===

HTML/Javascript
===
<script src="app/functions.js"></script>
<div id="holder"></div>
<button 
onclick="Server.hello(prompt('Name?')).useToReplace('holder');">Click 
me</button>
===



And when you click that button, the string D returns will be
put inside as text.

That's the basic of it.




I'm taking this to an extreme with this:

http://arsdnet.net:8080/

(that's my custom D web server, so if it doesn't respond, I 
probably
closed the program. Will leave it open for a while though.)


Click on the link and the body. You should get some text added.



Take a look at the javascript though:
http://arsdnet.net:8080/sse.js


	document.body.addEventListener("click", function(event) {
		var response = Test.cancelableEvent(
			event.type,
			event.target.getAttribute("data-node-index")
		).getSync();
  [snip]



It uses synchronous ajax on the click handler to forward the
event to the server, which then passes it through the server
side dom.


D:
===

/* the library implements EventResponse cancelableEvent(...),
which dispatches the event on the server, so you can write: */

         // body is a keyword in D, hence mainBody instead.
document.mainBody.addEventListener("click"), (Event ev) {
     ev.target.appendText("got click!");
     ev.preventDefault();
});

===


sync ajax requests suck because it blocks the whole web app
waiting for a response. But writing server side event handlers
is a fun toy.








I do write real applications with web.d, but they are almost
all proprietary, so little toys is all I really have to show
right now.


More information about the Digitalmars-d mailing list