[erlang-questions] ANN: ezwebframe - an easy web framework

Christopher Meiklejohn cmeiklejohn@REDACTED
Wed Dec 19 16:53:16 CET 2012

On Wednesday, December 19, 2012 at 6:58 AM, Joe Armstrong wrote:
> > But how the browser understand the commands you send from erlang process? for 
> > example here: {cmd, fill_div}
> This is easy, here's an overview:
> - Convert the Erlang command to JSON
> - send the JSON on the websocket uing Erlang
> - receive the JSON in Javascript
> - parse the JSON
> - build a Javascript command
> - execute the Javascript command

Hi Joe,

Thank you for putting this out there, I had a great time digging through the source code learning how the examples worked.  

I found it so inspiring that I went off and started playing around with some alternative approaches to handling the messages on the JavaScript side.  See here: [1]

I've been exploring having the messages, when received on the JavaScript side, distributed using a pub/sub approach so the Erlang code doesn't have to know about JavaScript function names or argument lists.  I felt this made it feel a bit less RPC-ish and made it feel a bit more idiomatic.  See below for examples.

One thing that I couldn't get a hold of when playing with your code was if you intended to write *most* of the client side application in Erlang and just write a thin-layer in JavaScript for event handling and DOM-manipulation or if you were leaving that up to the developer.

Again, thanks so much!


For example (partially taken from the README):

Given the following Erlang:

BrowserPid ! {client_count, 1}. 

The following message is sent on the wire:
{ type: "client_count", message: "1" } 

Followed by the following message published via AmplifyJS:
amplify.publish("client_count", 1);

This allows multiple consumers in your JavaScript application to subscribe to these messages and respond to them accordingly.  A subscriber could then call a method to update the DOM with that new value (via jQuery or whatever, this is no longer specific).

[1] https://github.com/cmeiklejohn/piper


Christopher Meiklejohn
Software Engineer
Basho Technologies, Inc. 

More information about the erlang-questions mailing list