Re: Websockets API / CloseEvent and readyState

On Thu, 18 Mar 2010, Olli Pettay wrote:
> 
> I was wondering why to have .wasClean in close event. Is there really 
> need for adding yet another event interface. Especially in this case 
> when there are other quite simple options.

An event interface doesn't seem like much of a burden. Event interfaces 
are so similar to each other that it's pretty simple to just autogenerate 
their code by this point.


> WebSocket could have state ERROR and then in the close event listener 
> the script could check whether connection was closed normally, or 
> whether the state is ERROR and based on that try to reconnect.

That doesn't seem very consistent with other readyState attributes. It 
would also make checking whether the connection is open or not a bit less 
trivial.


> In the script the change would be from
>
> function closelistener(e) {
>   if (e.wasClean) {
>     dosomething();
>   } else {
>     reconnect();
>   }
> }
> 
> to
>
> function closelistener(e) {
>   if (this.readyState == this.CLOSED) {
>     dosomething();
>   } else {
>     reconnect();
>   }
> }

The first one of these seems simpler.


> .wasClean feels and sounds bad :/

I don't really see why. If it's just the name then I'm happy to change it 
to something else.

Does anyone else have an opinion on this?

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'

Received on Wednesday, 14 April 2010 23:18:04 UTC