Skip to content

Make Room into an object? #40

@ehaughee

Description

@ehaughee

Currently the code operates on arbitrary hashes as concepts of "rooms". I suggest we make an object that looks like the following (assuming no ES6):

var Room = {};
var Room = function (name) {
    this.name = name;
    this.users = [];
};

Room.prototype.addUser = function(user) {
    if (user) {
        this.users.push();
    }
}

Room.prototype.removeUser = function(user) {
    if (user) {
        // Assuming underscore
        this.users = _.without(users, user);
        return true;
    }
    return false;
}

function generateRoomName(length) {
    ...
}

module.exports = function(rooms) {
    var name = "";
    rooms = _.isArray(rooms) ? rooms : []; 

    do {
        name = getRoomName();
    } while(_.contains(rooms, name)); // assuming underscore

    return new Room(name);
}

A Rooms object might also be in order to allow room adding, removing, and unique name definition without passing around all the rooms from an external source.

var Rooms = function () {
    this.rooms = [];
}

Rooms.prototype.addRoom(room) {
    // use above code to create new room
}

Rooms.prototype.removeRoom(room) {
    ...
}

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions