-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: switch uic live execution declaratively with observable
- Loading branch information
1 parent
9e2571d
commit 81960ec
Showing
2 changed files
with
24 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,38 @@ | ||
import { concatMap, firstValueFrom, switchMap } from 'rxjs' | ||
import { concatMap, of, switchMap } from 'rxjs' | ||
import type { URI } from 'vscode-uri' | ||
import { | ||
getLiveExecutionEnabledFromConfig$, | ||
getLiveExecutionGlobFromConfig$, | ||
} from '../configurations' | ||
import type { SupportedTool } from '../types' | ||
import { getWatcher$ } from '../watcher' | ||
import { compileUi } from './compile-ui' | ||
|
||
export function registerUicLiveExecution$({ | ||
extensionUri, | ||
}: GetUicLiveExecutionArgs) { | ||
return getLiveExecutionGlobFromConfig$({ | ||
const onUiFileUpdated$ = getLiveExecutionGlobFromConfig$({ | ||
tool: 'uic', | ||
resource: undefined, | ||
defaultValue: '**/*.ui', | ||
}).pipe( | ||
switchMap(glob => getWatcher$(glob)), | ||
concatMap(uri => onUiFileUpdated({ uri, extensionUri })), | ||
switchMap(global => getWatcher$(global)), | ||
concatMap(uri => compileUi({ extensionUri }, uri)), | ||
) | ||
} | ||
|
||
type GetUicLiveExecutionArgs = { readonly extensionUri: URI } | ||
return getLiveExecutionEnabledFromConfig$({ | ||
tool: 'uic', | ||
resource: undefined, | ||
}).pipe( | ||
switchMap(enabled => { | ||
if (!enabled) | ||
return of({ | ||
kind: 'Success', | ||
value: 'uic live execution disabled', | ||
} as const) | ||
|
||
async function onUiFileUpdated({ uri, extensionUri }: OnUiFileUpdatedArgs) { | ||
const tool: SupportedTool = 'uic' | ||
const enabled = await firstValueFrom( | ||
getLiveExecutionEnabledFromConfig$({ tool, resource: uri }), | ||
return onUiFileUpdated$ | ||
}), | ||
) | ||
|
||
if (!enabled) | ||
return { kind: 'Success', value: 'Live execution disabled' } as const | ||
|
||
return compileUi({ extensionUri }, uri) | ||
} | ||
|
||
type OnUiFileUpdatedArgs = { | ||
readonly extensionUri: URI | ||
readonly uri: URI | ||
} | ||
type GetUicLiveExecutionArgs = { readonly extensionUri: URI } |