messages now a bit different, less contructions

not constructing one for each possible message but only constructing when message happens
This commit is contained in:
2020-02-16 23:17:46 +01:00
parent 23c1ec33a1
commit e3792005ba
7 changed files with 52 additions and 51 deletions

View File

@@ -15,7 +15,7 @@ class View:
patch(container, self.vdom)
# this does not work on parent div, so attaching to document here
document.addEventListener("keyup", msg(KeyboardPress()))
document.addEventListener("keyup", msg(KeyboardPress))
def view(self, model):
self.model = model
@@ -26,8 +26,8 @@ class View:
self.vdom = new_vdom
def _view(self):
return h("div", {"on": { "click": msg(Reset()) }}, [
View.view_entry(self.model.entry, self.model),
return h("div", {"on": { "click": msg(Reset) }}, [
self.model.entry.view(self.model),
h("button.blk", {"on": { "click": lambda _: check_export(self.model) } }, "CHK"),
View.view_menu(self.model.menu_location, self.model.menu_target, self.model.entry),
View.view_modal(self.model.modal_shown, self.model.modal)])
@@ -57,8 +57,8 @@ class View:
txt_examples = "Hide examples" if model.examples_shown else "Show examples"
txt_clusters = "Hide clusters" if model.clusters_shown else "Show clusters"
return [h("span.button.toggle", {"on": {"click": msg(ToggleExamples())}}, txt_examples),
h("span.button.toggle", {"on": {"click": msg(ToggleClusters())}}, txt_clusters)]
return [h("span.button.toggle", {"on": {"click": msg(ToggleExamples)}}, txt_examples),
h("span.button.toggle", {"on": {"click": msg(ToggleClusters)}}, txt_clusters)]
@staticmethod
@@ -148,7 +148,7 @@ class View:
return h("div.example", {"style": {"display": parent_display}}, [
h("div.example-dot", dot_attr, ""),
h(example_tag, {}, [
h("span.example-text", {"on": {"click": msg(ShowExampleMenu(example))} }, example_content),
h("span.example-text", {"on": {"click": msg(ShowExampleMenu, example)} }, example_content),
h("div.example-translation-list", {}, [
h("div.example-translation", {}, View.view_translations(example.translations, example, model))]),
h("div.example-clusters",
@@ -160,7 +160,7 @@ class View:
for cluster in translations:
result.append(h("div.translation-div-cluster", {}, [View.view_one_translation(t, model) for t in cluster]))
result.append(h("button.add-button", {"on": {"click": msg(ShowAddTranslation(parent))}}, "+"))
result.append(h("button.add-button", {"on": {"click": msg(ShowAddTranslation, parent)}}, "+"))
return result
@staticmethod
@@ -180,7 +180,7 @@ class View:
explanation_class = ".translation-explanation" if translation.translation else ""
elements.append(h("span{}".format(explanation_class), {}, translation.explanation))
return h("div.translation-div", {"on": {"click": msg(ShowTranslationMenu(translation)) }}, elements)
return h("div.translation-div", {"on": {"click": msg(ShowTranslationMenu, translation) }}, elements)
@staticmethod
@@ -197,26 +197,26 @@ class View:
elif type(menu_target) is Translation:
translation = menu_target
return h("span.popup-menu", { "style": style }, [
h("button.shyButton", { "on": {"click": msg(ShowEditTranslation(translation))}}, ""),
h("button.shyButton", { "on": {"click": msg(MoveRight(translation))}}, ""),
h("button.shyButton", { "on": {"click": msg(MoveLeft(translation))}}, ""),
h("button.shyButton", { "on": {"click": msg(BinTranslation(translation))}}, "🗑")])
h("button.shyButton", { "on": {"click": msg(ShowEditTranslation, translation)}}, ""),
h("button.shyButton", { "on": {"click": msg(MoveRight, translation)}}, ""),
h("button.shyButton", { "on": {"click": msg(MoveLeft, translation)}}, ""),
h("button.shyButton", { "on": {"click": msg(BinTranslation, translation)}}, "🗑")])
elif type(menu_target) is Sense:
sense = menu_target
return h("span.popup-menu", { "style": style }, [
h("button.shyButton", { "on": {"click": msg(SenseMoveUp(sense))}}, ""),
h("button.shyButton", { "on": {"click": msg(SenseMoveDown(sense))}}, ""),
h("button.shyButton", { "on": {"click": msg(SenseBin(sense))}}, "🗑")])
h("button.shyButton", { "on": {"click": msg(SenseMoveUp, sense)}}, ""),
h("button.shyButton", { "on": {"click": msg(SenseMoveDown, sense)}}, ""),
h("button.shyButton", { "on": {"click": msg(SenseBin, sense)}}, "🗑")])
elif type(menu_target) is Example:
example = menu_target
sense = example_sense(example, entry)
return h("span.popup-menu", { "style": style }, [
h("button.shyButton", { "on": {"click": msg(ShowExampleEdit(example, sense))}}, ""),
h("button.shyButton", { "on": {"click": msg(ExampleMoveUp(example))}}, ""),
h("button.shyButton", { "on": {"click": msg(ExampleMoveDown(example))}}, ""),
h("button.shyButton", { "on": {"click": msg(ExampleBin(example))}}, "🗑")])
h("button.shyButton", { "on": {"click": msg(ShowExampleEdit, example, sense)}}, ""),
h("button.shyButton", { "on": {"click": msg(ExampleMoveUp, example)}}, ""),
h("button.shyButton", { "on": {"click": msg(ExampleMoveDown, example)}}, ""),
h("button.shyButton", { "on": {"click": msg(ExampleBin, example)}}, "🗑")])
else:
console.log("Should not be heree!!")
@@ -226,5 +226,5 @@ class View:
return h("div.modal", {}, [
h("input", { "props": {"type": "checkbox", "checked": modal_shown} }, ""),
h("label.overlay", {}, ""),
h("article", {"on": { "click": msg(NoReset()) }}, modal())])
h("article", {"on": { "click": msg(NoReset) }}, modal())])