📄 bridge¶
📊 Analysis Summary¶
| Metric | Count |
|---|---|
| 🔧 Functions | 3 |
| 📦 Imports | 4 |
📚 Table of Contents¶
🛠️ File Location:¶
📂 packages/website/src/components/linter/bridge.ts
📦 Imports¶
| Name | Source |
|---|---|
ConfigModel |
../types |
PlaygroundSystem |
./types |
debounce |
../lib/debounce |
getPathRegExp |
./utils |
Functions¶
createFileSystem(config: Pick<ConfigModel, 'code' | 'eslintrc' |…, vfs: typeof tsvfs): PlaygroundSystem¶
Parameters:
configPick<ConfigModel, 'code' | 'eslintrc' | 'fileType' | 'tsconfig'>vfstypeof tsvfs
Returns: PlaygroundSystem
Calls:
files.setvfs.createSystemdebounce (from ../lib/debounce)getPathRegExp (from ./utils)fileWatcherCallbacks.getfileWatcherCallbacks.sethandle.addfileWatcherCallbacks.get(expPath)?.deletefileWatcherCallbacks.forEachkey.testcallbacks.forEachcbfiles.deletetriggerCallbacksfiles.get[...files.keys()].filterfiles.keysexpPath.test[...files.keys()] .filter(fileName => !fileName.startsWith('/lib.')) .filterf.endsWith
Internal Comments:
Code
export function createFileSystem(
config: Pick<ConfigModel, 'code' | 'eslintrc' | 'fileType' | 'tsconfig'>,
vfs: typeof tsvfs,
): PlaygroundSystem {
const files = new Map<string, string>();
files.set(`/.eslintrc`, config.eslintrc);
files.set(`/tsconfig.json`, config.tsconfig);
if (config.code !== '') {
files.set(`/input${config.fileType}`, config.code);
}
const fileWatcherCallbacks = new Map<RegExp, Set<ts.FileWatcherCallback>>();
const system = vfs.createSystem(files) as PlaygroundSystem;
system.watchFile = (
path,
callback,
pollingInterval = 500,
): ts.FileWatcher => {
const cb = pollingInterval ? debounce(callback, pollingInterval) : callback;
const expPath = getPathRegExp(path);
let handle = fileWatcherCallbacks.get(expPath);
if (!handle) {
handle = new Set();
fileWatcherCallbacks.set(expPath, handle);
}
handle.add(cb);
return {
close: (): void => {
fileWatcherCallbacks.get(expPath)?.delete(cb);
},
};
};
const triggerCallbacks = (
path: string,
type: ts.FileWatcherEventKind,
): void => {
fileWatcherCallbacks.forEach((callbacks, key) => {
if (key.test(path)) {
callbacks.forEach(cb => cb(path, type));
}
});
};
system.deleteFile = (fileName): void => {
files.delete(fileName);
triggerCallbacks(fileName, 1);
};
system.writeFile = (fileName, contents): void => {
if (!contents) {
contents = '';
}
const file = files.get(fileName);
if (file === contents) {
// do not trigger callbacks if the file has not changed
return;
}
files.set(fileName, contents);
triggerCallbacks(fileName, file ? 2 : 0);
};
system.removeFile = (fileName): void => {
files.delete(fileName);
};
system.searchFiles = (path: string): string[] => {
const expPath = getPathRegExp(path);
return [...files.keys()].filter(fileName => expPath.test(fileName));
};
system.getScriptFileNames = (): string[] => {
return [...files.keys()]
.filter(fileName => !fileName.startsWith('/lib.'))
.filter(f => !f.endsWith('/.eslintrc') && !f.endsWith('.json'));
};
return system;
}
Internal helpers¶
Declared inside another function in this file.
close(): void¶
Returns: void
Calls:
fileWatcherCallbacks.get(expPath)?.delete
triggerCallbacks(path: string, type: ts.FileWatcherEventKind): void¶
Parameters:
pathstringtypets.FileWatcherEventKind
Returns: void
Calls:
fileWatcherCallbacks.forEachkey.testcallbacks.forEachcb
Code
Generated by Syntax Scribe