Type may now be either a String or a Number.#175
Type may now be either a String or a Number.#175Schoonology wants to merge 1 commit intoJustinTulloss:masterfrom
Conversation
This is what the docstring claims, and is now correct.
There was a problem hiding this comment.
so _type is the numerical version of type?
I reckon it makes sense to rename that a little bit to reflect that difference?
There was a problem hiding this comment.
I think we need 2 properties and make this.type always be string, and this._type (I propose this.inttype) always be int.
Then we could make fill the both fields disregarding of what has been passed as the type argument.
// normalize this.inttype
this.inttype = typeof type === 'number' ? type : types[type];
// normalize this.type
Object.keys(types).forEach(function(type) {
if (types[type] == this.inttype) { this.type = type; }
}, this);There was a problem hiding this comment.
To be fair, I see most code using zmq just opting for the string version of Socket, and that might be a "nicer" method regardless.
In that case, I'd remove support for initializing from a Number entirely, opting to only use Socket(String).
There was a problem hiding this comment.
@Schoonology actually according to http://api.zeromq.org/3-2:zmq-socket initializing socket with int seems more correct.
This is what the docstring for the Socket constructor claims, and is now correct.
Side Effect:
There is now a
_typeproperty on all returned Socket objects._typeis always a Number, corresponding directly to the ZMQ enum.I could have opted to use the existing
typeproperty this way, but that seems of minor importance, and I decided compatibility with existing expectations was most important. If that should be changed, let me know.