fix: handle better forced value propagation in apps

This commit is contained in:
Ruben Fiszel
2025-02-21 17:37:25 +01:00
parent 6d11bb4a00
commit 3ac912fa30
3 changed files with 22 additions and 22 deletions

View File

@@ -316,10 +316,12 @@
}
}
function onValueChange(newValue: any): void {
function onValueChange(newValue: any, force?: boolean): void {
if (iterContext && $iterContext.disabled) return
if (lastInput?.type === 'connected' && newValue !== undefined && newValue !== null) {
if (
lastInput?.type === 'connected' &&
((newValue !== undefined && newValue !== null) || force)
) {
const { connection } = lastInput
if (!connection) {
// No connection

View File

@@ -4,7 +4,7 @@ import { deepEqual } from 'fast-equals'
import sum from 'hash-sum'
export interface Subscriber<T> {
id?: string
next(v: T): void
next(v: T, force?: boolean): void
}
export interface Observable<T> {
@@ -23,7 +23,7 @@ export type World = {
outputsById: Record<string, Record<string, Output<any>>>
connect: <T>(
connection: InputConnectionEval,
next: (x: T) => void,
next: (x: T, force?: boolean) => void,
id: string,
previousValue: any
) => Input<T>
@@ -79,7 +79,7 @@ export function buildObservableWorld() {
return {
id,
peak: () => undefined,
next: () => {}
next: () => { }
}
}
@@ -95,7 +95,7 @@ export function buildObservableWorld() {
}
return {
peak: () => undefined,
next: () => {}
next: () => { }
}
}
@@ -119,16 +119,16 @@ export function buildObservableWorld() {
newOutput
}
}
export function cachedInput<T>(nextParan: (x: T) => void, id?: string): Input<T> {
export function cachedInput<T>(nextParam: (x: T, force?: boolean) => void, id?: string): Input<T> {
let value: T | undefined = undefined
function peak(): T | undefined {
return value
}
function next(x: T): void {
function next(x: T, force?: boolean): void {
value = x
nextParan(x)
nextParam(x, force)
}
return {
@@ -152,7 +152,7 @@ export function settableOutput<T>(state: Writable<number>, previousValue: T): Ou
// Send the current value to the new subscriber if it already exists
if (value !== undefined && !deepEqual(value, npreviousValue)) {
x.next(value)
x.next(value, false)
}
// return a callback to unsubscribe
@@ -180,7 +180,7 @@ export function settableOutput<T>(state: Writable<number>, previousValue: T): Ou
} else {
value = x
}
subscribers.forEach((x) => x.next(value!))
subscribers.forEach((x) => x.next(value!, force))
}
}

View File

@@ -89,7 +89,7 @@
let maxTs = $page.url.searchParams.get('max_ts') ?? undefined
let schedulePath = $page.url.searchParams.get('schedule_path') ?? undefined
let jobKindsCat = $page.url.searchParams.get('job_kinds') ?? 'runs'
let allWorkspaces = $page.url.searchParams.get('all_workspaces') == 'true' ?? false
let allWorkspaces = $page.url.searchParams.get('all_workspaces') == 'true'
let lastFetchWentToEnd = false
function loadFromQuery() {
@@ -135,7 +135,7 @@
maxTs = $page.url.searchParams.get('max_ts') ?? undefined
schedulePath = $page.url.searchParams.get('schedule_path') ?? undefined
jobKindsCat = $page.url.searchParams.get('job_kinds') ?? 'runs'
allWorkspaces = $page.url.searchParams.get('all_workspaces') == 'true' ?? false
allWorkspaces = $page.url.searchParams.get('all_workspaces') == 'true'
}
let queue_count: Tweened<number> | undefined = undefined
@@ -639,13 +639,12 @@
}}
/>
{#if $userStore?.operator && $workspaceStore && !$userWorkspaces.find(_ => _.id === $workspaceStore)?.operator_settings?.runs}
<div class="bg-red-100 border-l-4 border-red-600 text-orange-700 p-4 m-4 mt-12" role="alert">
<p class="font-bold">Unauthorized</p>
<p>Page not available for operators</p>
</div>
{:else}
{#if innerWidth > 900}
{#if $userStore?.operator && $workspaceStore && !$userWorkspaces.find((_) => _.id === $workspaceStore)?.operator_settings?.runs}
<div class="bg-red-100 border-l-4 border-red-600 text-orange-700 p-4 m-4 mt-12" role="alert">
<p class="font-bold">Unauthorized</p>
<p>Page not available for operators</p>
</div>
{:else if innerWidth > 900}
<div class="w-full h-screen">
<div class="px-2">
<div class="flex items-center space-x-2 flex-row justify-between">
@@ -1377,4 +1376,3 @@
</div>
</div>
{/if}
{/if}