Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

html and client fixes #368

Merged
merged 18 commits into from
Mar 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lona/client/_lona/client/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ SOFTWARE.
*/

import { LonaWindowShim } from './window-shim.js';
import { LonaWindowShim } from '../client2/window-shim.js';
import { LonaWindow } from './window.js';
import { Lona } from './lona.js';

Expand Down
33 changes: 19 additions & 14 deletions lona/client/_lona/client/dom-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,25 @@ SOFTWARE.

*/

import { LonaWindowShim } from './window-shim.js';
import { Widget } from '../client2/widget.js';
import { Lona } from './lona.js';


export class LonaDomRenderer {
constructor(lona_context, lona_window) {
this.lona_context = lona_context;
this.lona_window = lona_window;

this._dom_parser = new DOMParser();
};

_parse_html_string(html_string) {
return this._dom_parser.parseFromString(
html_string,
'text/html',
).documentElement.textContent;
}

// html rendering ---------------------------------------------------------
_render_node(node_spec) {
var property_names = ['value', 'checked', 'selected'];
Expand Down Expand Up @@ -114,25 +123,23 @@ export class LonaDomRenderer {
throw(`RuntimeError: unknown widget name '${widget_class_name}'`);
}

var widget_class = Lona.widget_classes[widget_class_name];

var window_shim = new LonaWindowShim(
const widget = new Widget(
this.lona_context,
this.lona_window,
node,
node_id,
Lona.widget_classes[widget_class_name],
widget_data,
);

var widget = new widget_class(window_shim);

this.lona_window._widgets[node_id] = widget;
this.lona_window._widget_data[node_id] = widget_data;
this.lona_window._widgets_to_setup.splice(0, 0, node_id);
}

// TextNode
} else if(node_type == Lona.protocol.NODE_TYPE.TEXT_NODE) {
var node_id = node_spec[1];
var node_content = node_spec[2];
var node_content = this._parse_html_string(node_spec[2]);

var node = document.createTextNode(node_content);

Expand Down Expand Up @@ -170,18 +177,16 @@ export class LonaDomRenderer {

// setup widget
if(node_widget_class_name in Lona.widget_classes) {
var widget_class = Lona.widget_classes[node_widget_class_name];

var window_shim = new LonaWindowShim(
const widget = new Widget(
this.lona_context,
this.lona_window,
node,
node_id,
Lona.widget_classes[widget_class_name],
widget_data,
);

var widget = new widget_class(window_shim);

this.lona_window._widgets[node_id] = widget;
this.lona_window._widget_data[node_id] = widget_data;
this.lona_window._widgets_to_setup.splice(0, 0, node_id);
};
};
Expand Down
13 changes: 6 additions & 7 deletions lona/client/_lona/client/dom-updater.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,12 @@ export class LonaDomUpdater {

_remove_node(node_id) {

// TextNode
// Node
if(node_id in this.lona_window._nodes) {
this.lona_window._nodes[node_id].remove();
node = this.lona_window._nodes[node_id];

node.remove();
this.lona_window._remove_widget_if_present(node_id);

delete this.lona_window._nodes[node_id];

Expand Down Expand Up @@ -310,11 +313,7 @@ export class LonaDomUpdater {
node.remove();
};

// Node
} else {
node = this.lona_window._nodes[node_id];

node.remove();
this.lona_window._remove_widget_if_present(node_id);
};
};

Expand Down
8 changes: 5 additions & 3 deletions lona/client/_lona/client/widget-data-updater.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ export class LonaWidgetDataUpdater {
var key_path = payload[0];
var data = payload.splice(1);

const widget = this.lona_window._widgets[node_id];

// key path
var parent_data = undefined;
var widget_data = this.lona_window._widget_data[node_id];
let widget_data = widget.raw_widget_data;

key_path.forEach(function(key) {
parent_data = widget_data;
Expand All @@ -56,7 +58,7 @@ export class LonaWidgetDataUpdater {
// RESET
} else if(operation == Lona.protocol.OPERATION.RESET) {
if(parent_data === undefined) {
this.lona_window._widget_data[node_id] = data[0];
widget.raw_widget_data = data[0];

} else {
parent_data = data[0];
Expand All @@ -74,7 +76,7 @@ export class LonaWidgetDataUpdater {
};

if(parent_data === undefined) {
this.lona_window._widget_data[node_id] = new_data;
widget.raw_widget_data = new_data;

} else {
parent_data[key_path[key_path.length-1]] = new_data;
Expand Down
49 changes: 0 additions & 49 deletions lona/client/_lona/client/window-shim.js

This file was deleted.

Loading