({ channel, session, children }: ProviderPropsType)
| 30 | * An interface for working with tsconfig.json. |
| 31 | */ |
| 32 | export function TsConfigProvider({ channel, session, children }: ProviderPropsType) { |
| 33 | const [source, setSource] = useState(session['tsconfig.json'] || ''); |
| 34 | const [validationError, setValidationError] = useState<string | null>(null); |
| 35 | |
| 36 | const onChangeSource = useCallback( |
| 37 | (source: string) => { |
| 38 | setSource(source); |
| 39 | |
| 40 | const error = getValidationError(source); |
| 41 | setValidationError(error); |
| 42 | |
| 43 | if (error === null) { |
| 44 | channel.push('tsconfig.json:update', { |
| 45 | source, |
| 46 | }); |
| 47 | } |
| 48 | }, |
| 49 | [setSource, channel, setValidationError], |
| 50 | ); |
| 51 | |
| 52 | const context: TsConfigContextValue = { |
| 53 | source, |
| 54 | onChangeSource, |
| 55 | validationError, |
| 56 | }; |
| 57 | |
| 58 | return <TsConfigContext.Provider value={context}>{children}</TsConfigContext.Provider>; |
| 59 | } |
| 60 | |
| 61 | export function useTsconfigJson() { |
| 62 | const context = useContext(TsConfigContext); |
nothing calls this directly
no test coverage detected