cburschka / cadence

A strophe.js-powered XMPP web client for chatrooms.
6 stars 2 forks source link

Make JID a classed object #363

Closed cburschka closed 8 years ago

cburschka commented 8 years ago

There is so much pain that we're currently dealing with while handling JID strings. Every little method in cadence that needs to access a part of it has to call Strophe's parser functions - and every time we need the node value, we have to also unescape it.

It sure would be awesome if Javascript had object orientation.

oh wait it totally does now

https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Classes

Here's the idea: Make all JIDs instances of a JID class as soon as they hit our code. Run them through a parser in every handler, and only store the object.

Make the JID class a subclass of String, and initialize the supertype with the JID's string value.

This way, we can access the JID properties as easily as jid.node, jid.domain, jid.resource, but the JID also looks like a string (and supports all string methods like .split()), so it can be passed directly to Strophe whenever stanzas are constructed.