Created
October 13, 2015 07:23
-
-
Save startswithaj/ef410b67bcd80b9a272f to your computer and use it in GitHub Desktop.
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
Athlete = require './athlete' | |
module.exports = class AthleteList | |
@fromArray: (data, entryClass = Athlete) -> new @ data, entryClass | |
constructor: (data, @entryClass = Athlete) -> @updateFromArray data | |
updateFromArray: (data) -> | |
@members ?= {} | |
for entryData in data | |
@set @entryClass.fromObject entryData | |
return @ | |
size: -> Object.keys(@members).length | |
has: (id) -> @members[id]? | |
get: (id) -> @members[id] | |
all: -> _.values @members | |
set: (member) -> @members[member.id] = member | |
remove: (id) -> delete @members[id] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment