Skip to content

Commit

Permalink
Add debounced arc read to file watcher ✨
Browse files Browse the repository at this point in the history
  • Loading branch information
Freymaurer committed Nov 22, 2023
1 parent 39bf9ca commit 603f967
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 13 deletions.
15 changes: 8 additions & 7 deletions packages/renderer/src/ArcControlService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ function relativePath_to_absolute(relativePath: string) {
return ArcControlService.props.arc_root + '/' + relativePath
}

const ArcControlService = {

const ArcControlService = {

props: reactive(init),

closeARC: async() => {
ArcControlService.props.arc_root = null;
ArcControlService.props.busy = false;
Expand All @@ -44,18 +45,18 @@ const ArcControlService = {
AppProperties.state = 0;
return;
},

readARC: async (arc_root: string | void | null) =>{
if(!arc_root)
if(!arc_root)
arc_root = ArcControlService.props.arc_root;
if(!arc_root)
return;
return;

const isARC = await window.ipc.invoke('LocalFileSystemService.exists', arc_root+'/isa.investigation.xlsx');

if (!isARC) {
ArcControlService.closeARC();
return false;
ArcControlService.closeARC();
return false;
}

ArcControlService.props.busy = true;
Expand Down
21 changes: 19 additions & 2 deletions packages/renderer/src/views/ArcTreeView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,26 @@ const onSelectionChanged = id =>{
}
};
const asyncDebounce = (mainFunction, delay) => {
// Declare a variable called 'timer' to store the timer ID
let timer: NodeJS.Timeout;
// Return an anonymous function that takes in any number of arguments
return function (...args) {
// Clear the previous timer to prevent the execution of 'mainFunction'
clearTimeout(timer);
// Set a new timer that will execute 'mainFunction' after the specified delay
timer = setTimeout(async () => {
await mainFunction(...args);
}, delay);
};
};
const debounceReadARC = asyncDebounce(ArcControlService.readARC, 300);
const updatePath = async path => {
console.log("updatePath", path)
console.log("arcTree", arcTree)
debounceReadARC();
if (!arcTree.value)
return;
const n = arcTree._value.getNodeByKey(path);
Expand Down
5 changes: 4 additions & 1 deletion packages/renderer/src/views/AssayView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ const iProps = reactive({
const init = async ()=>{
if(!ArcControlService.props.arc || !AppProperties.active_assay) return;
iProps.assay = ArcControlService.props.arc.ISA.GetAssay(AppProperties.active_assay);
const assay = ArcControlService.props.arc.ISA.TryGetAssay(AppProperties.active_assay);
if (!assay) return;
iProps.assay = assay
};
onMounted( init );
Expand Down
8 changes: 5 additions & 3 deletions packages/renderer/src/views/StudyView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ const iProps = reactive({
const init = async ()=>{
if(!ArcControlService.props.arc || !AppProperties.active_study) return;
iProps.study = ArcControlService.props.arc.ISA.GetStudy(AppProperties.active_study);
iProps.people = iProps.study.Contacts;
iProps.publications = iProps.study.Publications;
const study = ArcControlService.props.arc.ISA.TryGetStudy(AppProperties.active_study);
if (!study) return;
iProps.study = study
iProps.people = study.Contacts;
iProps.publications = study.Publications;
};
onMounted( init );
Expand Down

0 comments on commit 603f967

Please sign in to comment.