Skip to content

Commit

Permalink
always run inputs that havent run yet
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfcosta committed Nov 20, 2024
1 parent 67dd3e1 commit ba60032
Showing 1 changed file with 40 additions and 6 deletions.
46 changes: 40 additions & 6 deletions packages/editor/src/blocks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,13 @@ export const requestRun = <B extends YBlock>(
skipDependencyCheck: boolean,
customOnRequestRun?: (block: B) => void
) => {
const dependencies = skipDependencyCheck
? []
: computeDepencyQueue(block, layout, blocks, environmentStartedAt)
const dependencies = computeDepencyQueue(
block,
layout,
blocks,
environmentStartedAt,
skipDependencyCheck
)

const queue = dependencies
if (!customOnRequestRun) {
Expand Down Expand Up @@ -334,6 +338,22 @@ export function isExecutableBlock(block: YBlock): boolean {
})
}

export function isInputBlock(block: YBlock): boolean {
return switchBlockType(block, {
onPython: () => false,
onSQL: () => false,
onVisualization: () => false,
onInput: () => true,
onDropdownInput: () => true,
onWriteback: () => false,
onDateInput: () => true,
onRichText: () => false,
onFileUpload: () => false,
onDashboardHeader: () => false,
onPivotTable: () => false,
})
}

export function duplicateYText(text: Y.Text): Y.Text {
const newText = new Y.Text()
newText.insert(0, text.toString())
Expand Down Expand Up @@ -393,12 +413,25 @@ function getExecutedAt(block: YBlock, blocks: Y.Map<YBlock>): Date | null {
function mustExecute(
block: YBlock,
blocks: Y.Map<YBlock>,
environmentStartedAt: Date | null
environmentStartedAt: Date | null,
skipDependencyCheck: boolean
): boolean {
if (!isExecutableBlock(block)) {
return false
}

// We should always run input blocks if they have not been run yet
// even if skipDependencyCheck is true
if (skipDependencyCheck) {
const lastExecutedAt = getExecutedAt(block, blocks)
const lastExecutedAtIsAfterEnvironmentStartedAt =
lastExecutedAt === null ||
environmentStartedAt === null ||
dfns.isAfter(environmentStartedAt, lastExecutedAt)

return isInputBlock(block) && lastExecutedAtIsAfterEnvironmentStartedAt
}

if (environmentStartedAt === null) {
return true
}
Expand All @@ -415,7 +448,8 @@ export function computeDepencyQueue(
block: YBlock,
layout: Y.Array<YBlockGroup>,
blocks: Y.Map<YBlock>,
environmentStartedAt: Date | null
environmentStartedAt: Date | null,
skipDependencyCheck: boolean
): YBlock[] {
const flatLayout = layout
.toArray()
Expand All @@ -438,7 +472,7 @@ export function computeDepencyQueue(

const blocksBefore = flatLayout.slice(0, blockIndex)
const blocksBeforeToRun = blocksBefore.filter((block) =>
mustExecute(block, blocks, environmentStartedAt)
mustExecute(block, blocks, environmentStartedAt, skipDependencyCheck)
)

return blocksBeforeToRun
Expand Down

0 comments on commit ba60032

Please sign in to comment.