Skip to content

Commit

Permalink
Removed starting node assumption in useRunNode (#979)
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment committed Sep 16, 2022
1 parent 251363b commit 3215153
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/renderer/hooks/useRunNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import log from 'electron-log';
import { useEffect, useMemo, useRef } from 'react';
import { useContext } from 'use-context-selector';
import { NodeData } from '../../common/common-types';
import { delay, getInputValues, isStartingNode } from '../../common/util';
import { delay, getInputValues } from '../../common/util';
import { AlertBoxContext } from '../contexts/AlertBoxContext';
import { BackendContext } from '../contexts/BackendContext';
import { GlobalContext } from '../contexts/GlobalNodeState';
Expand All @@ -25,6 +25,8 @@ export const useRunNode = ({ inputData, id, schemaId }: NodeData, shouldRun: boo

const schema = schemata.get(schemaId);

const didEverRun = useRef(false);

const inputs = useMemo(
() => getInputValues(schema, (inputId) => inputData[inputId] ?? null),
[inputData]
Expand All @@ -43,6 +45,7 @@ export const useRunNode = ({ inputData, id, schemaId }: NodeData, shouldRun: boo
lastInputHash.current = inputHash;

if (shouldRun) {
didEverRun.current = true;
animate([id], false);

const result = await backend.runIndividual({
Expand Down Expand Up @@ -74,14 +77,8 @@ export const useRunNode = ({ inputData, id, schemaId }: NodeData, shouldRun: boo

useEffect(() => {
return () => {
// TODO: Change this if we ever make more than starting nodes run
if (isStartingNode(schema)) {
backend
.clearNodeCacheIndividual(id)
.then(() => {})
.catch((error) => {
log.error(error);
});
if (didEverRun.current) {
backend.clearNodeCacheIndividual(id).catch((error) => log.error(error));
}
};
}, []);
Expand Down

0 comments on commit 3215153

Please sign in to comment.