Skip to content
This repository was archived by the owner on Jan 9, 2025. It is now read-only.

Commit e6b08c8

Browse files
authored
Merge pull request #10 from github/fix-until-allow-non-promise-values-in-type
fix(until): allow non Promise values in type
2 parents 4d42680 + 38b6c0c commit e6b08c8

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

src/until.ts

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,21 @@ import {directive} from './directive'
33
import type {TemplatePart} from '@github/template-parts'
44

55
const untils: WeakMap<TemplatePart, {i: number}> = new WeakMap()
6-
export const until = directive<Array<Promise<unknown>>>(
7-
(...promises: Array<Promise<unknown>>) => (part: TemplatePart) => {
8-
if (!untils.has(part)) untils.set(part, {i: promises.length})
9-
const state = untils.get(part)!
10-
for (let i = 0; i < promises.length; i += 1) {
11-
if (promises[i] instanceof Promise) {
12-
// eslint-disable-next-line github/no-then
13-
Promise.resolve(promises[i]).then(value => {
14-
if (i < state.i) {
15-
state.i = i
16-
processPart(part, value)
17-
}
18-
})
19-
} else if (i <= state.i) {
20-
state.i = i
21-
processPart(part, promises[i])
22-
}
6+
export const until = directive((...promises: unknown[]) => (part: TemplatePart) => {
7+
if (!untils.has(part)) untils.set(part, {i: promises.length})
8+
const state = untils.get(part)!
9+
for (let i = 0; i < promises.length; i += 1) {
10+
if (promises[i] instanceof Promise) {
11+
// eslint-disable-next-line github/no-then
12+
Promise.resolve(promises[i]).then(value => {
13+
if (i < state.i) {
14+
state.i = i
15+
processPart(part, value)
16+
}
17+
})
18+
} else if (i <= state.i) {
19+
state.i = i
20+
processPart(part, promises[i])
2321
}
2422
}
25-
)
23+
})

0 commit comments

Comments
 (0)