-
Notifications
You must be signed in to change notification settings - Fork 13
Description
Hey there,
I came across your project and I really love it!
I recently realized that the Velox constructor on the client side doesn't allow for the obj parameter to be empty. Your examples use global objects like
// load script /velox.js
var foo = {};
var v = velox("/sync", foo);
v.onupdate = function() {
//foo.A === 42 and foo.B === 21
};As it can be seen, there are no requirements to the passed object besides being of type object.
However, since the onupdate callback passes this.obj as a parameter anyway, the object containing the received data doesn't need to be global (when using SSE, at least). Right now I'm using
var v = velox("/sync", {});
v.onupdate = function(obj) {
//obj.A === 42 and obj.B === 21
};to avoid using global objects, but this still looks a bit ugly. It would be better if the empty object could be omitted and instead be implicitly created by the constructor like velox("/sync").
I would therefore propose a change in the constructor of the Velox class like
obj = obj || {};
if (typeof obj !== "object") {
throw "Invalid object";
}
this.obj = obj;to implicitly create an empty object when the parameter obj is omitted instead of throwing an error.
Kindly
bliepp