Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit 81960ec

Browse files
committed
refactor: switch uic live execution declaratively with observable
1 parent 9e2571d commit 81960ec

File tree

2 files changed

+24
-29
lines changed

2 files changed

+24
-29
lines changed

src/rcc/rcc-live-execution.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ import { compileResource } from './compile-resource'
2525
export function registerRccLiveExecution$({
2626
extensionUri,
2727
}: RegisterRccLiveExecutionArgs) {
28-
const enabled$ = getLiveExecutionEnabledFromConfig$({
29-
tool: 'rcc',
30-
resource: undefined,
31-
})
32-
3328
const glob$ = getLiveExecutionGlobFromConfig$({
3429
tool: 'rcc',
3530
resource: undefined,
@@ -43,21 +38,24 @@ export function registerRccLiveExecution$({
4338

4439
const watcher$ = glob$.pipe(switchMap(glob => getWatcher$(glob)))
4540

46-
const onQrcFileChange$ = merge(qrcFiles$, watcher$).pipe(
41+
const onQrcFileUpdated$ = merge(qrcFiles$, watcher$).pipe(
4742
mergeMap(qrcUri =>
4843
registerResourcesLiveExecution$({ extensionUri, qrcUri }),
4944
),
5045
)
5146

52-
return enabled$.pipe(
47+
return getLiveExecutionEnabledFromConfig$({
48+
tool: 'rcc',
49+
resource: undefined,
50+
}).pipe(
5351
switchMap(enabled => {
5452
if (!enabled)
5553
return of({
5654
kind: 'Success',
57-
value: 'Live execution disabled',
55+
value: 'rcc live execution disabled',
5856
} as const)
5957

60-
return onQrcFileChange$
58+
return onQrcFileUpdated$
6159
}),
6260
)
6361
}

src/uic/uic-live-execution.ts

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,38 @@
1-
import { concatMap, firstValueFrom, switchMap } from 'rxjs'
1+
import { concatMap, of, switchMap } from 'rxjs'
22
import type { URI } from 'vscode-uri'
33
import {
44
getLiveExecutionEnabledFromConfig$,
55
getLiveExecutionGlobFromConfig$,
66
} from '../configurations'
7-
import type { SupportedTool } from '../types'
87
import { getWatcher$ } from '../watcher'
98
import { compileUi } from './compile-ui'
109

1110
export function registerUicLiveExecution$({
1211
extensionUri,
1312
}: GetUicLiveExecutionArgs) {
14-
return getLiveExecutionGlobFromConfig$({
13+
const onUiFileUpdated$ = getLiveExecutionGlobFromConfig$({
1514
tool: 'uic',
1615
resource: undefined,
1716
defaultValue: '**/*.ui',
1817
}).pipe(
19-
switchMap(glob => getWatcher$(glob)),
20-
concatMap(uri => onUiFileUpdated({ uri, extensionUri })),
18+
switchMap(global => getWatcher$(global)),
19+
concatMap(uri => compileUi({ extensionUri }, uri)),
2120
)
22-
}
2321

24-
type GetUicLiveExecutionArgs = { readonly extensionUri: URI }
22+
return getLiveExecutionEnabledFromConfig$({
23+
tool: 'uic',
24+
resource: undefined,
25+
}).pipe(
26+
switchMap(enabled => {
27+
if (!enabled)
28+
return of({
29+
kind: 'Success',
30+
value: 'uic live execution disabled',
31+
} as const)
2532

26-
async function onUiFileUpdated({ uri, extensionUri }: OnUiFileUpdatedArgs) {
27-
const tool: SupportedTool = 'uic'
28-
const enabled = await firstValueFrom(
29-
getLiveExecutionEnabledFromConfig$({ tool, resource: uri }),
33+
return onUiFileUpdated$
34+
}),
3035
)
31-
32-
if (!enabled)
33-
return { kind: 'Success', value: 'Live execution disabled' } as const
34-
35-
return compileUi({ extensionUri }, uri)
3636
}
3737

38-
type OnUiFileUpdatedArgs = {
39-
readonly extensionUri: URI
40-
readonly uri: URI
41-
}
38+
type GetUicLiveExecutionArgs = { readonly extensionUri: URI }

0 commit comments

Comments
 (0)