( prev: readonly T[] | undefined, item: T, )
| 106 | * a new array (AppState immutability). |
| 107 | */ |
| 108 | export function appendCappedMessage<T>( |
| 109 | prev: readonly T[] | undefined, |
| 110 | item: T, |
| 111 | ): T[] { |
| 112 | if (prev === undefined || prev.length === 0) { |
| 113 | return [item] |
| 114 | } |
| 115 | if (prev.length >= TEAMMATE_MESSAGES_UI_CAP) { |
| 116 | const next = prev.slice(-(TEAMMATE_MESSAGES_UI_CAP - 1)) |
| 117 | next.push(item) |
| 118 | return next |
| 119 | } |
| 120 | return [...prev, item] |
| 121 | } |
| 122 |
no test coverage detected