Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
hannahblair committed Jun 4, 2024
1 parent 182045e commit 70e074d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 23 deletions.
48 changes: 35 additions & 13 deletions client/js/src/helpers/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,23 +136,45 @@ export function handle_payload(
dependency: Dependency,
components: ComponentMeta[],
with_null_state = false
): unknown[] {
let payload_index = 0;
): any[] {
try {
let payload_index = 0;
let updated_payload: unknown[] = [];

dependency.inputs.forEach((input_id) => {
const component = components.find((c) => c.id === input_id);
if (component?.type === "state") {
if (with_null_state) {
updated_payload.push(null);
}
if (!with_null_state) payload_index++;
} else {
const value = resolved_payload[payload_index];
updated_payload.push(value);
payload_index++;
}
});

return updated_payload;
} catch (e) {
console.error(e);
return resolved_payload;
}
}

export function build_payload(
resolved_payload: unknown[],
dependency: Dependency,
components: ComponentMeta[]
): any[] {
let updated_payload: unknown[] = [];

dependency.inputs.forEach((input_id) => {
const component = components.find((c) => c.id === input_id);
dependency.inputs.map((input_id: number, index: number): any => {
const component = components.find((c: any) => c.id === input_id);
if (component?.type === "state") {
if (with_null_state) {
updated_payload.push(null);
}
if (!with_null_state) payload_index++;
} else {
const value = resolved_payload[payload_index];
updated_payload.push(value);
payload_index++;
return null;
}
updated_payload.push(resolved_payload[index]);
});

return updated_payload;
}
4 changes: 3 additions & 1 deletion client/js/src/utils/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ export async function open_stream(this: Client): Promise<void> {
} else if (event_callbacks[event_id] && config) {
if (
_data.msg === "process_completed" &&
["sse", "sse_v1", "sse_v2", "sse_v2.1"].includes(config.protocol)
["sse", "sse_v1", "sse_v2", "sse_v2.1", "sse_v3"].includes(
config.protocol
)
) {
unclosed_events.delete(event_id);
if (unclosed_events.size === 0) {
Expand Down
19 changes: 10 additions & 9 deletions client/js/src/utils/submit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ import type {
Dependency
} from "../types";

import { skip_queue, post_message, handle_payload } from "../helpers/data";
import {
skip_queue,
post_message,
handle_payload,
build_payload
} from "../helpers/data";
import { resolve_root } from "../helpers/init_helpers";
import {
handle_message,
Expand Down Expand Up @@ -193,14 +198,9 @@ export function submit(

this.handle_blob(config.root, resolved_data, endpoint_info).then(
async (_payload) => {
let input_data = handle_payload(
_payload,
dependency,
config.components,
true
);
let input_data = build_payload(_payload, dependency, config.components);
payload = {
data: input_data || [],
data: input_data || _payload || [],
event_data,
fn_index,
trigger_id
Expand Down Expand Up @@ -231,7 +231,8 @@ export function submit(
type: "data",
endpoint: _endpoint,
fn_index,
data: handle_payload(data, dependency, config.components),
// data: handle_payload(data, dependency, config.components),
data: data,
time: new Date(),
event_data,
trigger_id
Expand Down

0 comments on commit 70e074d

Please sign in to comment.