UNPKG

616 BJavaScriptView Raw
1import { getId } from '../util'
2
3// Have to use a real class to get working inheritance from Array. Methods are
4// still added inside wrapWaitlist, as usual.
5class Waitlist extends Array {}
6
7export default function wrapWaitlist (mp, waitlist) {
8 const wrapped = Object.assign(new Waitlist(), {
9 contains: (user) =>
10 wrapped.some((waiting) => waiting.id === getId(user)),
11 positionOf: (user) =>
12 wrapped.findIndex((waiting) => waiting.id === getId(user)),
13 toJSON: () => waitlist
14 })
15
16 waitlist.forEach((id) => {
17 wrapped.push(mp.user(id) || mp.wrapUser({ id: id }))
18 })
19
20 return wrapped
21}