From 416d733510eff6eaefa0b3144084cdaaeacaa4af Mon Sep 17 00:00:00 2001 From: zadam Date: Sun, 19 Jan 2020 15:36:42 +0100 Subject: [PATCH] got rid of .renderTo(), tab caching widgets use hidden marker element --- .../javascripts/services/app_context.js | 22 +++++++++--- .../javascripts/widgets/basic_widget.js | 6 ---- src/public/javascripts/widgets/note_detail.js | 2 +- src/public/javascripts/widgets/note_paths.js | 4 +-- src/public/javascripts/widgets/note_title.js | 34 ++----------------- src/public/javascripts/widgets/note_type.js | 11 ++---- .../widgets/protected_note_switch.js | 15 ++++++++ .../javascripts/widgets/row_flex_container.js | 4 +-- .../javascripts/widgets/run_script_buttons.js | 29 +++++++--------- .../javascripts/widgets/tab_aware_widget.js | 2 +- .../javascripts/widgets/tab_caching_widget.js | 9 +++-- 11 files changed, 59 insertions(+), 79 deletions(-) diff --git a/src/public/javascripts/services/app_context.js b/src/public/javascripts/services/app_context.js index 5c8e8d24d..700e13184 100644 --- a/src/public/javascripts/services/app_context.js +++ b/src/public/javascripts/services/app_context.js @@ -24,6 +24,11 @@ import RowFlexContainer from "../widgets/row_flex_container.js"; import StandardTopWidget from "../widgets/standard_top_widget.js"; import treeCache from "./tree_cache.js"; import treeUtils from "./tree_utils.js"; +import NotePathsWidget from "../widgets/note_paths.js"; +import RunScriptButtonsWidget from "../widgets/run_script_buttons.js"; +import ProtectedNoteSwitchWidget from "../widgets/protected_note_switch.js"; +import NoteTypeWidget from "../widgets/note_type.js"; +import NoteActionsWidget from "../widgets/note_actions.js"; class AppContext { constructor() { @@ -51,7 +56,7 @@ class AppContext { const $topPane = $("#top-pane"); for (const widget of topPaneWidgets) { - widget.renderTo($topPane); + $topPane.append(widget.render()); } const $leftPane = $("#left-pane"); @@ -66,19 +71,26 @@ class AppContext { ]; for (const widget of leftPaneWidgets) { - widget.renderTo($leftPane); + $leftPane.append(widget.render()); } const $centerPane = $("#center-pane"); const centerPaneWidgets = [ - new TabCachingWidget(this, () => new NoteTitleWidget(this)), + new RowFlexContainer(this, [ + new TabCachingWidget(this, () => new NotePathsWidget(this)), + new NoteTitleWidget(this), + new RunScriptButtonsWidget(this), + new ProtectedNoteSwitchWidget(this), + new NoteTypeWidget(this), + new NoteActionsWidget(this) + ]), new TabCachingWidget(this, () => new PromotedAttributesWidget(this)), new TabCachingWidget(this, () => new NoteDetailWidget(this)) ]; for (const widget of centerPaneWidgets) { - widget.renderTo($centerPane); + $centerPane.append(widget.render()); } const $rightPane = $("#right-pane"); @@ -93,7 +105,7 @@ class AppContext { ]; for (const widget of rightPaneWidgets) { - widget.renderTo($rightPane); + $rightPane.append(widget.render()); } this.widgets = [ diff --git a/src/public/javascripts/widgets/basic_widget.js b/src/public/javascripts/widgets/basic_widget.js index 5c1fd5f7c..c553c4599 100644 --- a/src/public/javascripts/widgets/basic_widget.js +++ b/src/public/javascripts/widgets/basic_widget.js @@ -1,12 +1,6 @@ import Component from "./component.js"; class BasicWidget extends Component { - renderTo($parent) { - this.$parent = $parent; - - $parent.append(this.render()); - } - render() { return this.doRender(); } diff --git a/src/public/javascripts/widgets/note_detail.js b/src/public/javascripts/widgets/note_detail.js index 8b9fc6615..fd12edd08 100644 --- a/src/public/javascripts/widgets/note_detail.js +++ b/src/public/javascripts/widgets/note_detail.js @@ -92,7 +92,7 @@ export default class NoteDetailWidget extends TabAwareWidget { this.typeWidgets[this.type] = new clazz.default(this.appContext); this.children.push(this.typeWidgets[this.type]); - this.typeWidgets[this.type].renderTo(this.$widget); + this.$widget.append(this.typeWidgets[this.type].render()); this.typeWidgets[this.type].eventReceived('setTabContext', {tabContext: this.tabContext}); } diff --git a/src/public/javascripts/widgets/note_paths.js b/src/public/javascripts/widgets/note_paths.js index 893282358..7b70bb9ca 100644 --- a/src/public/javascripts/widgets/note_paths.js +++ b/src/public/javascripts/widgets/note_paths.js @@ -30,9 +30,7 @@ export default class NotePathsWidget extends TabAwareWidget { return this.$widget; } - async refreshWithNote() { - const {note, notePath} = this.tabContext; - + async refreshWithNote(note, notePath) { if (note.noteId === 'root') { // root doesn't have any parent, but it's still technically 1 path diff --git a/src/public/javascripts/widgets/note_title.js b/src/public/javascripts/widgets/note_title.js index c78c49eba..15e867b2d 100644 --- a/src/public/javascripts/widgets/note_title.js +++ b/src/public/javascripts/widgets/note_title.js @@ -12,12 +12,8 @@ import ProtectedNoteSwitchWidget from "./protected_note_switch.js"; import RunScriptButtonsWidget from "./run_script_buttons.js"; const TPL = ` -
+