feat(routers): add observed router inventory and scoped controls
Separate router discovery, evidence and authorized control from device runtime. Add Node/Core contracts and reusable operator surfaces.
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
import {useEffect,useState} from 'react';
|
||||
import type {RouterSnapshot,RouterTransport} from './contracts';
|
||||
|
||||
export function useRouters(transport:RouterTransport){
|
||||
const [value,setValue]=useState<RouterSnapshot|null>(null),[error,setError]=useState('');
|
||||
useEffect(()=>{
|
||||
let active=true;let timer:ReturnType<typeof setTimeout>;
|
||||
setValue(null);setError('');
|
||||
async function poll(){
|
||||
try{const next=await transport.read();if(active){setValue(next);setError('');}}
|
||||
catch{if(active){setValue(previous=>previous?{...previous,fresh:false}:previous);setError('Не удалось обновить сведения о роутере.');}}
|
||||
finally{if(active)timer=setTimeout(()=>void poll(),3000);}
|
||||
}
|
||||
void poll();return()=>{active=false;clearTimeout(timer);};
|
||||
},[transport]);
|
||||
return {value,error};
|
||||
}
|
||||
Reference in New Issue
Block a user