diff --git a/lona/client/_lona/context.js b/lona/client/_lona/context.js index 23de39d0..ff9fe69f 100644 --- a/lona/client/_lona/context.js +++ b/lona/client/_lona/context.js @@ -1,45 +1,48 @@ -Lona.LonaContext = function(settings) { - // settings --------------------------------------------------------------- - this.settings = settings || {}; - this.settings.target = this.settings.target || '#lona'; - this.settings.title = this.settings.title || ''; - - if(typeof(this.settings.update_address_bar) == 'undefined') { - this.settings.update_address_bar = true; - }; +Lona.LonaContext = class LonaContext { + constructor(settings) { + this.settings = settings || {}; + this.settings.target = this.settings.target || '#lona'; + this.settings.title = this.settings.title || ''; + + if(typeof(this.settings.update_address_bar) == 'undefined') { + this.settings.update_address_bar = true; + }; - if(typeof(this.settings.update_title) == 'undefined') { - this.settings.update_title = true; - }; + if(typeof(this.settings.update_title) == 'undefined') { + this.settings.update_title = true; + }; - if(typeof(this.settings.follow_redirects) == 'undefined') { - this.settings.follow_redirects = true; - }; + if(typeof(this.settings.follow_redirects) == 'undefined') { + this.settings.follow_redirects = true; + }; - if(typeof(this.settings.follow_http_redirects) == 'undefined') { - this.settings.follow_http_redirects = true; - }; + if(typeof(this.settings.follow_http_redirects) == 'undefined') { + this.settings.follow_http_redirects = true; + }; - if(typeof(this.settings.scroll_to_top_on_view_start) == 'undefined') { - this.settings.scroll_to_top_on_view_start = true; - }; + if(typeof(this.settings.scroll_to_top_on_view_start) == 'undefined') { + this.settings.scroll_to_top_on_view_start = true; + }; - // state ------------------------------------------------------------------ - this._windows = {}; - this._connect_hooks = []; - this._disconnect_hooks = []; - this._rendering_hooks = []; - this._view_timeout_hooks = []; - this._input_event_timeout_hooks = []; - this._message_handler = []; + this._windows = {}; + this._last_window_id = 0; + this._connect_hooks = []; + this._disconnect_hooks = []; + this._rendering_hooks = []; + this._view_timeout_hooks = []; + this._input_event_timeout_hooks = []; + this._message_handler = []; + }; // window ----------------------------------------------------------------- - this.create_window = function(root, url) { + create_window(root, url) { if(typeof(root) == 'string') { root = document.querySelector(root); }; - var window_id = Object.keys(this._windows).length + 1; + this._last_window_id += 1; + + var window_id = this._last_window_id; this._windows[window_id] = new Lona.LonaWindow( this, root, window_id, url); @@ -50,9 +53,7 @@ Lona.LonaContext = function(settings) { }; // input events ----------------------------------------------------------- - this.patch_input_events = function(root_node_selector, window_id) { - var _this = this; - + patch_input_events(root_node_selector, window_id) { // find window if(window_id == undefined) { window_id = 1; @@ -64,37 +65,37 @@ Lona.LonaContext = function(settings) { var node = document.querySelector(root_node_selector); var selector = 'a,form,[data-lona-events]'; - node.querySelectorAll(selector).forEach(function(node) { + node.querySelectorAll(selector).forEach(node => { _window._input_event_handler.patch_input_events(node); }); }; // hooks ------------------------------------------------------------------ - this.add_connect_hook = function(hook) { + add_connect_hook(hook) { this._connect_hooks.push(hook); }; - this.add_disconnect_hook = function(hook) { + add_disconnect_hook(hook) { this._disconnect_hooks.push(hook); }; - this.add_rendering_hook = function(hook) { + add_rendering_hook(hook) { this._rendering_hooks.push(hook); }; - this.add_view_timeout_hook = function(hook) { + add_view_timeout_hook(hook) { this._view_timeout_hooks.push(hook); }; - this.add_input_event_timeout_hook = function(hook) { + add_input_event_timeout_hook(hook) { this._input_event_timeout_hooks.push(hook); }; - this.add_message_handler = function(handler) { + add_message_handler(handler) { this._message_handler.push(handler); }; - this._run_connect_hooks = function(event) { + _run_connect_hooks(event) { for(var i in this._connect_hooks) { var hook = this._connect_hooks[i]; @@ -102,7 +103,7 @@ Lona.LonaContext = function(settings) { }; }; - this._run_disconnect_hooks = function(event) { + _run_disconnect_hooks(event) { for(var i in this._disconnect_hooks) { var hook = this._disconnect_hooks[i]; @@ -110,7 +111,7 @@ Lona.LonaContext = function(settings) { }; }; - this._run_rendering_hooks = function(lona_window) { + _run_rendering_hooks(lona_window) { try { for(var i in this._rendering_hooks) { var hook = this._rendering_hooks[i]; @@ -124,7 +125,7 @@ Lona.LonaContext = function(settings) { }; }; - this._run_view_timeout_hooks = function(lona_window) { + _run_view_timeout_hooks(lona_window) { var lona_window_shim = new Lona.LonaWindowShim(this, lona_window); try { @@ -140,7 +141,7 @@ Lona.LonaContext = function(settings) { }; }; - this._run_input_event_timeout_hooks = function(lona_window) { + _run_input_event_timeout_hooks(lona_window) { var lona_window_shim = new Lona.LonaWindowShim(this, lona_window); try { @@ -156,7 +157,7 @@ Lona.LonaContext = function(settings) { }; }; - this._run_message_handler = function(message) { + _run_message_handler(message) { for(var i in this._message_handler) { var message_handler = this._message_handler[i]; @@ -169,7 +170,7 @@ Lona.LonaContext = function(settings) { }; // websocket messages ----------------------------------------------------- - this.send = function(message) { + send(message) { if(typeof(message) != 'string') { message = JSON.stringify(message); }; @@ -179,7 +180,7 @@ Lona.LonaContext = function(settings) { this._ws.send(message); }; - this._handle_raw_websocket_message = function(event) { + _handle_raw_websocket_message(event) { var raw_message = event.data; var json_data = undefined; @@ -226,7 +227,7 @@ Lona.LonaContext = function(settings) { }; // pings ------------------------------------------------------------------ - this.send_ping = function() { + send_ping() { var raw_message = [ undefined, // window_id undefined, // view_runtime_id @@ -242,24 +243,22 @@ Lona.LonaContext = function(settings) { this.send(message); }; - this._send_pings = function() { - var _this = this; - + _send_pings() { setTimeout( - function() { - if(_this._ws.readyState != _this._ws.OPEN) { + () => { + if(this._ws.readyState != this._ws.OPEN) { return; }; - _this.send_ping(); - _this._send_pings(); + this.send_ping(); + this._send_pings(); }, Lona.settings.PING_INTERVAL * 1000, ); }; // setup ------------------------------------------------------------------ - this.reconnect = function() { + reconnect() { // state this._windows = {}; @@ -310,17 +309,26 @@ Lona.LonaContext = function(settings) { }; }; - this.setup = function() { - var _this = this; - - _this.reconnect(); + setup() { + this.reconnect(); // unset websocket.onclose handler when page gets unloaded to // prevent the browser from showing "Server disconnected" when the // user changes the browser URL - window.addEventListener('beforeunload', function(event) { - _this._ws.onclose = function(event) {}; - _this._ws.close(); + window.addEventListener('beforeunload', event => { + this._ws.onclose = event => {}; + this._ws.close(); }); }; + + // shortcuts -------------------------------------------------------------- + get_default_window() { + return this._windows[1]; + }; + + run_view(url, post_data) { + var window = this.get_default_window(); + + return window.run_view(url, post_data); + }; }; diff --git a/lona/client/_lona/dom-renderer.js b/lona/client/_lona/dom-renderer.js index 489d9efb..f709881d 100644 --- a/lona/client/_lona/dom-renderer.js +++ b/lona/client/_lona/dom-renderer.js @@ -1,10 +1,11 @@ -Lona.LonaDomRenderer = function(lona_context, lona_window) { - this.lona_context = lona_context; - this.lona_window = lona_window; +Lona.LonaDomRenderer = class LonaDomRenderer { + constructor(lona_context, lona_window) { + this.lona_context = lona_context; + this.lona_window = lona_window; + }; // html rendering --------------------------------------------------------- - this._render_node = function(node_spec) { - var _this = this; + _render_node(node_spec) { var property_names = ['value', 'checked', 'selected']; var node_list = []; @@ -27,7 +28,7 @@ Lona.LonaDomRenderer = function(lona_context, lona_window) { // id list if(node_id_list.length > 0) { - _this.lona_window._dom_updater._add_id(node, node_id_list); + this.lona_window._dom_updater._add_id(node, node_id_list); }; // class list @@ -37,14 +38,14 @@ Lona.LonaDomRenderer = function(lona_context, lona_window) { // style if(Object.keys(node_style).length > 0) { - Object.keys(node_style).forEach(function(key) { + Object.keys(node_style).forEach(key => { node.style[key] = node_style[key]; }); }; // attributes if(Object.keys(node_attributes).length > 0) { - Object.keys(node_attributes).forEach(function(key) { + Object.keys(node_attributes).forEach(key => { var value = node_attributes[key]; // properties @@ -64,17 +65,17 @@ Lona.LonaDomRenderer = function(lona_context, lona_window) { }; // nodes - node_child_nodes.forEach(function(sub_node_argspec) { - var sub_node_list = _this._render_node( + node_child_nodes.forEach(sub_node_argspec => { + var sub_node_list = this._render_node( sub_node_argspec); - _this.lona_window._dom_updater._apply_node_list( + this.lona_window._dom_updater._apply_node_list( node, sub_node_list, ); }); - _this.lona_window._nodes[node_id] = node; + this.lona_window._nodes[node_id] = node; node_list.push(node); // TextNode @@ -84,7 +85,7 @@ Lona.LonaDomRenderer = function(lona_context, lona_window) { var node = document.createTextNode(node_content); - _this.lona_window._nodes[node_id] = node; + this.lona_window._nodes[node_id] = node; node_list.push(node); // Widget @@ -101,13 +102,13 @@ Lona.LonaDomRenderer = function(lona_context, lona_window) { var end_marker = document.createComment( 'end-lona-widget:' + node_id); - _this.lona_window._widget_marker[node_id] = start_marker; + this.lona_window._widget_marker[node_id] = start_marker; node_list.push(start_marker); // nodes - node_child_nodes.forEach(function(sub_node_argspec) { - var sub_node_list = _this._render_node( + node_child_nodes.forEach(sub_node_argspec => { + var sub_node_list = this._render_node( sub_node_argspec); node_list.push(sub_node_list); @@ -122,31 +123,30 @@ Lona.LonaDomRenderer = function(lona_context, lona_window) { var window_shim = new Lona.LonaWindowShim( lona_context, - _this.lona_window, + this.lona_window, node_id, ); 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); + 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); }; }; // patch input events - node_list.forEach(function(node) { - _this.lona_window._input_event_handler.patch_input_events(node); + node_list.forEach(node => { + this.lona_window._input_event_handler.patch_input_events(node); }); return node_list; }; - this._render_nodes = function(node_specs) { + _render_nodes(node_specs) { // TODO: get rid of this method and move functionality // into _render_node() - var _this = this; var node_list = []; for(var index in node_specs) { @@ -154,8 +154,8 @@ Lona.LonaDomRenderer = function(lona_context, lona_window) { }; // patch input events - node_list.forEach(function(node) { - _this.lona_window._input_event_handler.patch_input_events(node); + node_list.forEach(node => { + this.lona_window._input_event_handler.patch_input_events(node); }); return node_list; diff --git a/lona/client/_lona/dom-updater.js b/lona/client/_lona/dom-updater.js index 36855b65..c6494599 100644 --- a/lona/client/_lona/dom-updater.js +++ b/lona/client/_lona/dom-updater.js @@ -1,27 +1,27 @@ -Lona.LonaDomUpdater = function(lona_context, lona_window) { - this.lona_context = lona_context; - this.lona_window = lona_window; +Lona.LonaDomUpdater = class LonaDomUpdater { + constructor(lona_context, lona_window) { + this.lona_context = lona_context; + this.lona_window = lona_window; + }; // helper ----------------------------------------------------------------- - this._add_id = function(node, id) { + _add_id(node, id) { var id_list = node.id.split(' '); id_list = id_list.concat(id); node.id = id_list.join(' ').trim(); }; - this._remove_id = function(node, id) { + _remove_id(node, id) { var id_list = node.id.split(' '); id_list.pop(id); node.id = id_list.join(' ').trim(); }; - this._get_widget_nodes = function(node_id) { - var _this = this; - + _get_widget_nodes(node_id) { var node_list = []; - var widget_marker = _this.lona_window._widget_marker[node_id]; + var widget_marker = this.lona_window._widget_marker[node_id]; var end_marker_text = 'end-lona-widget:' + node_id; var cursor = 0; @@ -56,7 +56,7 @@ Lona.LonaDomUpdater = function(lona_context, lona_window) { }; // methods ---------------------------------------------------------------- - this._apply_node_list = function(node, node_list) { + _apply_node_list(node, node_list) { for(var index=0; index { value.push(option.value); }); @@ -41,7 +45,7 @@ Lona.LonaInputEventHandler = function(lona_context, lona_window) { return value; }; - this._clear_input_events = function(node) { + _clear_input_events(node) { node.onclick = undefined; node.oninput = undefined; node.onchange = undefined; @@ -49,7 +53,7 @@ Lona.LonaInputEventHandler = function(lona_context, lona_window) { node.onblur = undefined; }; - this._patch_link = function(node) { + _patch_link(node) { var lona_window = this.lona_window; node.onclick = function(event) { @@ -67,7 +71,7 @@ Lona.LonaInputEventHandler = function(lona_context, lona_window) { }; }; - this._patch_onclick = function(node, event_type) { + _patch_onclick(node, event_type) { var input_event_handler = this; var lona_window = this.lona_window; @@ -101,7 +105,7 @@ Lona.LonaInputEventHandler = function(lona_context, lona_window) { }; }; - this._patch_onchange = function(node, event_type) { + _patch_onchange(node, event_type) { var input_event_handler = this; var lona_window = this.lona_window; @@ -160,7 +164,7 @@ Lona.LonaInputEventHandler = function(lona_context, lona_window) { }; }; - this._patch_onsubmit = function(node) { + _patch_onsubmit(node) { node.onsubmit = function(event) { event.preventDefault(); @@ -169,13 +173,13 @@ Lona.LonaInputEventHandler = function(lona_context, lona_window) { var multi_selects = {}; this.querySelectorAll('select[multiple]').forEach( - function(select_node) { + select_node => { var name = select_node.name; multi_selects[select_node.name] = []; Array.from(select_node.selectedOptions).forEach( - function(option) { + option => { multi_selects[name].push(option.value); } ); @@ -225,7 +229,7 @@ Lona.LonaInputEventHandler = function(lona_context, lona_window) { }; }; - this._patch_onfocus = function(node, event_type) { + _patch_onfocus(node, event_type) { var input_event_handler = this; var lona_window = this.lona_window; @@ -248,7 +252,7 @@ Lona.LonaInputEventHandler = function(lona_context, lona_window) { }; }; - this._patch_onblur = function(node, event_type) { + _patch_onblur(node, event_type) { var input_event_handler = this; var lona_window = this.lona_window; @@ -271,7 +275,7 @@ Lona.LonaInputEventHandler = function(lona_context, lona_window) { }; }; - this._parse_data_lona_events = function(node) { + _parse_data_lona_events(node) { var event_types = {}; if(!node.hasAttribute('data-lona-events')) { @@ -281,7 +285,7 @@ Lona.LonaInputEventHandler = function(lona_context, lona_window) { var _event_types = node.getAttribute('data-lona-events'); _event_types = _event_types.split(';').filter(Boolean); - _event_types.forEach(function(event_type, index) { + _event_types.forEach((event_type, index) => { var raw_event_type = event_type.replace(':', ',') var event_type = raw_event_type.split(',').filter(Boolean); @@ -291,9 +295,7 @@ Lona.LonaInputEventHandler = function(lona_context, lona_window) { return event_types; }; - this.patch_input_events = function(node) { - var _this = this; - + patch_input_events(node) { if(node.nodeType != Node.ELEMENT_NODE) { return; }; @@ -318,36 +320,34 @@ Lona.LonaInputEventHandler = function(lona_context, lona_window) { }; // data-lona-input-events attribute - Object.keys(event_types).forEach(function(key) { + Object.keys(event_types).forEach(key => { var event_type = event_types[key]; // onclick if(key == Lona.protocol.INPUT_EVENT_TYPE.CLICK) { - _this._patch_onclick(node, event_type); + this._patch_onclick(node, event_type); // onchange / oninput } else if(key == Lona.protocol.INPUT_EVENT_TYPE.CHANGE) { - _this._patch_onchange(node, event_type); + this._patch_onchange(node, event_type); // onsubmit } else if(key == Lona.protocol.INPUT_EVENT_TYPE.SUBMIT) { - _this._patch_onsubmit(node, event_type); + this._patch_onsubmit(node, event_type); // onfocus } else if(key == Lona.protocol.INPUT_EVENT_TYPE.FOCUS) { - _this._patch_onfocus(node, event_type); + this._patch_onfocus(node, event_type); // onblur } else if(key == Lona.protocol.INPUT_EVENT_TYPE.BLUR) { - _this._patch_onblur(node, event_type); + this._patch_onblur(node, event_type); }; }); }; - this.fire_input_event = function(node, event_type, data) { - var _this = this; - + fire_input_event(node, event_type, data) { if(this.lona_window._crashed) { return; }; @@ -373,7 +373,7 @@ Lona.LonaInputEventHandler = function(lona_context, lona_window) { }; // send event message - var event_id = _this.gen_event_id(); + var event_id = this.gen_event_id(); var payload = [ event_id, @@ -386,8 +386,8 @@ Lona.LonaInputEventHandler = function(lona_context, lona_window) { ]; var message = [ - _this.lona_window._window_id, - _this.lona_window._view_runtime_id, + this.lona_window._window_id, + this.lona_window._view_runtime_id, Lona.protocol.METHOD.INPUT_EVENT, payload, ] @@ -397,14 +397,11 @@ Lona.LonaInputEventHandler = function(lona_context, lona_window) { JSON.stringify(message) ); - _this.lona_context.send(message); + this.lona_context.send(message); // setup timeout - _this._timeouts[event_id] = setTimeout(function() { - _this.lona_context._run_input_event_timeout_hooks(_this); + this._timeouts[event_id] = setTimeout(() => { + this.lona_context._run_input_event_timeout_hooks(this); }, Lona.settings.INPUT_EVENT_TIMEOUT * 1000); }; - - // setup ------------------------------------------------------------------ - this.reset(); }; diff --git a/lona/client/_lona/job-queue.js b/lona/client/_lona/job-queue.js deleted file mode 100644 index c951e1cf..00000000 --- a/lona/client/_lona/job-queue.js +++ /dev/null @@ -1,49 +0,0 @@ -Lona.JobQueue = function(lona_window) { - this._lona_window = lona_window; - this._promises = []; - - this._lock = function() { - var promise_resolve; - - var promise = new Promise(function(resolve, reject) { - promise_resolve = resolve; - }); - - promise.resolve = promise_resolve; - - var new_array_length = this._promises.push(promise); - - if(new_array_length == 1) { - promise.resolve(); - }; - - return promise; - }; - - this._unlock = function() { - this._promises.shift(); - - if(this._promises.length > 0) { - this._promises[0].resolve(); - }; - }; - - this.add = async function(callback) { - await this._lock(); - - try { - var promise = callback(); - - if(promise instanceof Promise) { - await promise; - }; - - } catch(error) { - this._lona_window.crash(error); - - } finally { - this._unlock(); - - }; - }; -}; diff --git a/lona/client/_lona/widget-data-updater.js b/lona/client/_lona/widget-data-updater.js index f00d3674..be9841a3 100644 --- a/lona/client/_lona/widget-data-updater.js +++ b/lona/client/_lona/widget-data-updater.js @@ -1,8 +1,10 @@ -Lona.LonaWidgetDataUpdater = function(lona_context, lona_window) { - this.lona_context = lona_context; - this.lona_window = lona_window; +Lona.LonaWidgetDataUpdater = class LonaWidgetDataUpdater { + constructor(lona_context, lona_window) { + this.lona_context = lona_context; + this.lona_window = lona_window; + }; - this._apply_patch = function(patch) { + _apply_patch(patch) { var node_id = patch[0]; var patch_type = patch[1]; var operation = patch[2]; diff --git a/lona/client/_lona/window-shim.js b/lona/client/_lona/window-shim.js index b6beb0ee..e0c67cf5 100644 --- a/lona/client/_lona/window-shim.js +++ b/lona/client/_lona/window-shim.js @@ -1,10 +1,12 @@ -Lona.LonaWindowShim = function(lona_context, lona_window, widget_id) { - this.lona_context = lona_context; +Lona.LonaWindowShim = class LonaWindowShim { + constructor(lona_context, lona_window, widget_id) { + this.lona_context = lona_context; - this._lona_window = lona_window; - this._widget_id = widget_id; + this._lona_window = lona_window; + this._widget_id = widget_id; + }; - this.fire_input_event = function(node, event_type, data) { + fire_input_event(node, event_type, data) { return this._lona_window._input_event_handler.fire_input_event( node || this._widget_id, event_type, @@ -12,7 +14,7 @@ Lona.LonaWindowShim = function(lona_context, lona_window, widget_id) { ); }; - this.set_html = function(html) { + set_html(html) { if(this._lona_window._view_running) { throw('RuntimeError: cannot set HTML while a view is running'); }; diff --git a/lona/client/_lona/window.js b/lona/client/_lona/window.js index 9815b4c8..4c2a29dc 100644 --- a/lona/client/_lona/window.js +++ b/lona/client/_lona/window.js @@ -1,47 +1,47 @@ -Lona.LonaWindow = function(lona_context, root, window_id) { - this.lona_context = lona_context; - this._root = root; - this._window_id = window_id; - this._view_start_timeout = undefined; - - this._job_queue = new Lona.JobQueue(this); - - this._input_event_handler = new Lona.LonaInputEventHandler( - lona_context, - this, - ); - - this._dom_renderer = new Lona.LonaDomRenderer( - lona_context, - this, - ); - - this._dom_updater = new Lona.LonaDomUpdater( - lona_context, - this, - ); - - this._widget_data_updater = new Lona.LonaWidgetDataUpdater( - lona_context, - this, - ); - - // window state ----------------------------------------------------------- - this._crashed = false; - this._view_running = false; - this._view_runtime_id = undefined; - this._url = ''; - this._nodes = {}; - this._widget_marker = {}; - this._widget_data = {}; - this._widgets = {}; - this._widgets_to_setup = []; - this._widgets_to_update = []; +Lona.LonaWindow = class LonaWindow { + constructor(lona_context, root, window_id) { + this.lona_context = lona_context; + this._root = root; + this._window_id = window_id; + this._view_start_timeout = undefined; + + this._input_event_handler = new Lona.LonaInputEventHandler( + lona_context, + this, + ); + + this._dom_renderer = new Lona.LonaDomRenderer( + lona_context, + this, + ); + + this._dom_updater = new Lona.LonaDomUpdater( + lona_context, + this, + ); + + this._widget_data_updater = new Lona.LonaWidgetDataUpdater( + lona_context, + this, + ); + + this._crashed = false; + this._view_running = false; + this._view_runtime_id = undefined; + this._url = ''; + this._nodes = {}; + this._widget_marker = {}; + this._widget_data = {}; + this._widgets = {}; + this._widgets_to_setup = []; + this._widgets_to_update = []; + }; // urls ------------------------------------------------------------------- - this._set_url = function(raw_url) { + _set_url(raw_url) { // parse pathname, search and hash - _raw_url = new URL(raw_url, window.location.origin); + var _raw_url = new URL(raw_url, window.location.origin); + _raw_url = _raw_url.pathname + _raw_url.search + _raw_url.hash; if(raw_url.startsWith('..')) { @@ -76,17 +76,17 @@ Lona.LonaWindow = function(lona_context, root, window_id) { this._url = url.pathname + url.search + url.hash; }; - this.get_url = function() { + get_url() { return this._url; }; // html rendering helper -------------------------------------------------- - this._clear = function() { + _clear() { this._root.innerHTML = ''; this._input_event_handler.reset(); }; - this._clear_node_cache = function() { + _clear_node_cache() { // running widget deconstructors for(var key in this._widgets) { if(this._widgets[key].deconstruct !== undefined) { @@ -103,66 +103,62 @@ Lona.LonaWindow = function(lona_context, root, window_id) { this._widgets_to_update = []; }; - this._clean_node_cache = function() { - var _this = this; - + _clean_node_cache() { // nodes - Object.keys(_this._nodes).forEach(function(key) { - var node = _this._nodes[key]; + Object.keys(this._nodes).forEach(key => { + var node = this._nodes[key]; - if(!_this._root.contains(node)) { - delete _this._nodes[key]; + if(!this._root.contains(node)) { + delete this._nodes[key]; }; }); - Object.keys(_this._widget_marker).forEach(function(key) { - var node = _this._widget_marker[key]; + Object.keys(this._widget_marker).forEach(key => { + var node = this._widget_marker[key]; // widget_marker - if(_this._root.contains(node)) { + if(this._root.contains(node)) { return; }; - delete _this._widget_marker[key]; + delete this._widget_marker[key]; // widget - if(key in _this._widgets) { + if(key in this._widgets) { // run deconstructor - if(_this._widgets[key].deconstruct !== undefined) { - _this._widgets[key].deconstruct(); + if(this._widgets[key].deconstruct !== undefined) { + this._widgets[key].deconstruct(); }; // remove widget - delete _this._widgets[key]; + delete this._widgets[key]; // remove widget data - delete _this._widget_data[key]; + delete this._widget_data[key]; // remove widget from _widgets_to_setup - if(_this._widgets_to_setup.indexOf(key) > -1) { - _this._widgets_to_setup.splice( - _this._widgets_to_setup.indexOf(key), 1); + if(this._widgets_to_setup.indexOf(key) > -1) { + this._widgets_to_setup.splice( + this._widgets_to_setup.indexOf(key), 1); }; // remove widget from _widgets_to_update - if(_this._widgets_to_update.indexOf(key) > -1) { - _this._widgets_to_update.splice( - _this._widgets_to_update.indexOf(key), 1); + if(this._widgets_to_update.indexOf(key) > -1) { + this._widgets_to_update.splice( + this._widgets_to_update.indexOf(key), 1); }; }; }); }; // hooks ------------------------------------------------------------------ - this._run_widget_hooks = function() { - var _this = this; - + _run_widget_hooks() { // setup - _this._widgets_to_setup.forEach(function(node_id) { - var widget = _this._widgets[node_id]; - var widget_data = _this._widget_data[node_id]; + this._widgets_to_setup.forEach(node_id => { + var widget = this._widgets[node_id]; + var widget_data = this._widget_data[node_id]; widget.data = JSON.parse(JSON.stringify(widget_data)); @@ -170,7 +166,7 @@ Lona.LonaWindow = function(lona_context, root, window_id) { return; }; - widget.nodes = _this._dom_updater._get_widget_nodes(node_id); + widget.nodes = this._dom_updater._get_widget_nodes(node_id); if(widget.setup !== undefined) { widget.setup(); @@ -178,9 +174,9 @@ Lona.LonaWindow = function(lona_context, root, window_id) { }); // data_updated - _this._widgets_to_update.forEach(function(node_id) { - var widget = _this._widgets[node_id]; - var widget_data = _this._widget_data[node_id]; + this._widgets_to_update.forEach(node_id => { + var widget = this._widgets[node_id]; + var widget_data = this._widget_data[node_id]; widget.data = JSON.parse(JSON.stringify(widget_data)); @@ -193,63 +189,59 @@ Lona.LonaWindow = function(lona_context, root, window_id) { }; }); - _this._widgets_to_setup = []; - _this._widgets_to_update = []; + this._widgets_to_setup = []; + this._widgets_to_update = []; }; - this._show_html = function(html) { - _this = this; - - _this._job_queue.add(function() { - var message_type = html[0]; - var data = html[1]; + _show_html(html) { + var message_type = html[0]; + var data = html[1]; - // HTML - if(message_type == Lona.protocol.DATA_TYPE.HTML) { - var selector = 'a,form,[data-lona-events]'; + // HTML + if (message_type == Lona.protocol.DATA_TYPE.HTML) { + var selector = 'a,form,[data-lona-events]'; - _this._root.innerHTML = data; - _this._clean_node_cache(); + this._root.innerHTML = data; + this._clean_node_cache(); - _this._root.querySelectorAll(selector).forEach(function(node) { - _this._input_event_handler.patch_input_events(node); - }); + this._root.querySelectorAll(selector).forEach(node => { + this._input_event_handler.patch_input_events(node); + }); - // HTML tree - } else if(message_type == Lona.protocol.DATA_TYPE.HTML_TREE) { - _this._clear_node_cache(); + // HTML tree + } else if(message_type == Lona.protocol.DATA_TYPE.HTML_TREE) { + this._clear_node_cache(); - var node_list = _this._dom_renderer._render_node(data) + var node_list = this._dom_renderer._render_node(data) - _this._clear(); - _this._dom_updater._apply_node_list(_this._root, node_list); + this._clear(); + this._dom_updater._apply_node_list(this._root, node_list); - // HTML update - } else if(message_type == Lona.protocol.DATA_TYPE.HTML_UPDATE) { - _this._widgets_to_setup = []; - _this._widgets_to_update = []; + // HTML update + } else if(message_type == Lona.protocol.DATA_TYPE.HTML_UPDATE) { + this._widgets_to_setup = []; + this._widgets_to_update = []; - data.forEach(function(patch) { - var patch_type = patch[1]; + data.forEach(patch => { + var patch_type = patch[1]; - if(patch_type == Lona.protocol.PATCH_TYPE.WIDGET_DATA) { - _this._widget_data_updater._apply_patch(patch); + if(patch_type == Lona.protocol.PATCH_TYPE.WIDGET_DATA) { + this._widget_data_updater._apply_patch(patch); - } else {; - _this._dom_updater._apply_patch(patch); + } else { + this._dom_updater._apply_patch(patch); - }; + }; - }); - }; + }); + }; - _this._run_widget_hooks(); - _this.lona_context._run_rendering_hooks(_this); - }); + this._run_widget_hooks(); + this.lona_context._run_rendering_hooks(this); }; // public api ------------------------------------------------------------- - this.crash = function(error) { + crash(error) { // encode message var error_string; @@ -275,7 +267,7 @@ Lona.LonaWindow = function(lona_context, root, window_id) { throw(error); }; - this._handle_websocket_message = function (message) { + _handle_websocket_message(message) { var window_id = message[0]; var view_runtime_id = message[1]; var method = message[2]; @@ -360,7 +352,7 @@ Lona.LonaWindow = function(lona_context, root, window_id) { }; }; - this.handle_websocket_message = function(message) { + handle_websocket_message(message) { if(this._crashed) { return; }; @@ -374,13 +366,11 @@ Lona.LonaWindow = function(lona_context, root, window_id) { }; }; - this.run_view = function(url, post_data) { + run_view(url, post_data) { // Save the requested url to only show HTML messages that are related // to this request. // This prevents glitches when switching urls fast. - var _this = this; - if(this._crashed) { return; }; @@ -427,12 +417,12 @@ Lona.LonaWindow = function(lona_context, root, window_id) { this.lona_context.send(message); // setup view start timeout - this._view_start_timeout = setTimeout(function() { - _this.lona_context._run_view_timeout_hooks(_this); + this._view_start_timeout = setTimeout(() => { + this.lona_context._run_view_timeout_hooks(this); }, Lona.settings.VIEW_START_TIMEOUT * 1000); }; - this.setup = function(url) { + setup(url) { this.run_view(url); }; }; diff --git a/lona/client_pre_compiler.py b/lona/client_pre_compiler.py index d8382e2d..2eefa02d 100644 --- a/lona/client_pre_compiler.py +++ b/lona/client_pre_compiler.py @@ -13,7 +13,6 @@ SOURCE_ROOT = os.path.join(os.path.dirname(__file__), 'client') SOURCE_FILES = [ - '_lona/job-queue.js', '_lona/window-shim.js', '_lona/dom-renderer.js', '_lona/dom-updater.js', diff --git a/lona/shell/commands/lona_views.py b/lona/shell/commands/lona_views.py index 5a572d1f..9015d938 100644 --- a/lona/shell/commands/lona_views.py +++ b/lona/shell/commands/lona_views.py @@ -195,7 +195,6 @@ def show_view_info(self, arguments): ['Thread ID', view_runtime.thread_ident], ['Thread Name', view_runtime.thread_name], ['View ID', view_runtime.view_runtime_id], - ['Multi user', repr(isinstance(view_runtime.request.user, list))], ['Daemon', repr(view_runtime.is_daemon)], ['Started at', str(view_runtime.started_at)], ['Stopped at', str(view_runtime.stopped_at or '-')], diff --git a/test_project/templates/lona/frontend.html b/test_project/templates/lona/frontend.html index 74576846..9d744a39 100644 --- a/test_project/templates/lona/frontend.html +++ b/test_project/templates/lona/frontend.html @@ -14,10 +14,6 @@

Lona Test Project

Application Started: - - - Pending Rendering Jobs: - - - Loaded Nodes: - @@ -137,16 +133,13 @@

Lona Test Project

document.querySelector('#enable-rendering-statistics').onclick = function(event) { event.preventDefault(); - var pending_rendering_jobs = document.querySelector('#pending-rendering-jobs'); var loaded_nodes = document.querySelector('#loaded-nodes'); var loaded_widgets = document.querySelector('#loaded-widgets'); - pending_rendering_jobs.innerHTML = ''; loaded_nodes.innerHTML = ''; loaded_widgets.innerHTML = ''; lona_context.add_rendering_hook(function(lona_window) { - pending_rendering_jobs.innerHTML = lona_context._windows[1]._job_queue._promises.length - 1; loaded_nodes.innerHTML = Object.keys(lona_context._windows[1]._nodes).length; loaded_widgets.innerHTML = Object.keys(lona_context._windows[1]._widget_marker).length; });