Skip to content

Commit

Permalink
Debug WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
gjmooney committed May 23, 2024
1 parent 73f5043 commit 4f495db
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion js/datagrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ export class DataGridModel extends DOMWidgetModel {
transforms: { deserialize: unpack_models as any },
renderers: {
deserialize: unpack_models as any,
serialize: pack_models as any,
serialize: debug as any,
},
corner_renderer: { deserialize: unpack_models as any },
default_renderer: { deserialize: unpack_models as any },
Expand All @@ -400,6 +400,40 @@ export class DataGridModel extends DOMWidgetModel {
_view_callbacks: ICallbacks;
}

function debug(value: any) {
const upm = debug_pack_models(value);
console.log('first', value);
console.log('upm', upm);
return upm;
}
const IPY_MODEL_ = 'IPY_MODEL_';

function debug_pack_models(
value: WidgetModel | Dict<WidgetModel> | WidgetModel[] | any,
widget?: WidgetModel,
): any | Dict<unknown> | string | (Dict<unknown> | string)[] {
if (Array.isArray(value)) {
console.log('array');
const model_ids: string[] = [];
for (const model of value) {
model_ids.push(pack_models(model, widget));
}
return model_ids;
} else if (value instanceof WidgetModel) {
console.log('widget model');
return `${IPY_MODEL_}${value.model_id}`;
} else if (value instanceof Object && typeof value !== 'string') {
console.log('object');
const packed: { [key: string]: string } = {};
for (const [key, sub_value] of Object.entries(value)) {
packed[key] = pack_models(sub_value, widget);
}
return packed;
} else {
return value;
}
}

/**
* Helper function to convert snake_case strings to camelCase.
* Assumes all strings are valid snake_case (all lowercase).
Expand Down

0 comments on commit 4f495db

Please sign in to comment.