-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract explanatory functions from mover.
- Loading branch information
Ryan Feline
committed
Aug 23, 2017
1 parent
df10104
commit f541733
Showing
1 changed file
with
8 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,17 @@ | ||
module.exports = function Mover(clientsAndRooms, emitter) { | ||
|
||
var emitToRoom = function (direction) { | ||
return function (room) { | ||
emitter.to(room).emit('direction', direction); | ||
} | ||
} | ||
|
||
return { | ||
moveIn: function (clientId, direction) { | ||
var rooms = clientsAndRooms[clientId]; | ||
|
||
Object.keys(rooms || {}) | ||
.map(function (room) { | ||
emitter.to(room).emit('direction', direction); | ||
}); | ||
.every(emitToRoom(direction)); | ||
} | ||
}; | ||
} |