syncing array in group.now, it turns into an object

21 views
Skip to first unread message

Hugh Anderson

unread,
Sep 16, 2012, 6:32:15 PM9/16/12
to no...@googlegroups.com
I am initializing an empty array in the nowjs.on('newgroup') event, so that each group created gets an empty userList array.
Immediately after I initialize it, I console.log it, and it is not an Array, but an Object.
I am unable to use it like an array, it makes entries like {'0': { memberName: 'test'}} instead of an array like [{memberName: 'test'}].
Is this a bug in nowjs?  Using the most recent version, 0.8.1

nowjs.on('newgroup', function (group) {
   console.log('Nowjs group created: ' + group.groupName);
   group.now.userList = [];
// i have also tried group.now.userList = new Array() here, same issue
   console.log('userList=' + Util.inspectObject(group.now.userList));
// this prints userList={} (brackets, not braces) 
   group.on('leave', function () {
       console.log('userList=' + Util.inspectObject(group.now.userList));
       var currentClientId = this.user.clientId;
       removeClient(group, currentClientId);
// this tries to do group.now.userList.splice to take a member out of the array, but it can't use group.now.userList like an array
       group.now.eventServerToClient('group.removeMember', null, currentClientId);
   });

   group.on('join', function () {
       console.log('userList=' + Util.inspectObject(group.now.userList));
       var currentClientId = this.user.clientId;
       var newUser = addClient(group, currentClientId, this.now.memberName);
// this tries to do group.now.userList.push to add a member to the array, but it can't use group.now.userList like an array 
       group.now.eventServerToClient('group.addMember', newUser, currentClientId);
   });
});
Message has been deleted

Hugh Anderson

unread,
Sep 16, 2012, 8:33:11 PM9/16/12
to no...@googlegroups.com
My server nowjs version is 0.7.0.  That seems to be the latest available to me, as a Windows user.  I installed using the instructions here:
The file served by my localhost:99/nowjs/now.js reports it is version 0.8.1 in the comments inside it, but it was served by my 0.7.0 nowjs Windows branch clone.

Thanks to anybody who can help.

Here is a simplified version of the code that demonstrates the problem.

var Util = require('util');
function inspectObject (obj) {
    return Util.inspect(obj, true, 7, true);
};
nowjs.on('newgroup', function (group) {
   console.log('Nowjs group created: ' + group.groupName);
   group.now.userList = [];
   console.log('userList=' + inspectObject(group.now.userList));
   group.now.userList.push({ memberName: 'test' });
   console.log('userList=' + inspectObject(group.now.userList));
});
nowjs.getGroup('testGroup');
Reply all
Reply to author
Forward
0 new messages