Skip to content

Instantly share code, notes, and snippets.

@startswithaj
Created October 13, 2015 07:23
Show Gist options
  • Save startswithaj/ef410b67bcd80b9a272f to your computer and use it in GitHub Desktop.
Save startswithaj/ef410b67bcd80b9a272f to your computer and use it in GitHub Desktop.
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