From 6c8074201d89a480f9b021f61cc6ff2eae7bb283 Mon Sep 17 00:00:00 2001 From: Brian Cully Date: Mon, 12 May 2025 11:41:58 -0400 Subject: js: put save event back --- main.mjs | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) (limited to 'main.mjs') diff --git a/main.mjs b/main.mjs index f0e4ed8..5f49097 100644 --- a/main.mjs +++ b/main.mjs @@ -2,16 +2,6 @@ import Fretboard, { fretToNote } from './fretboard.mjs'; import KeyPicker from './key-picker.mjs'; import History from './history.mjs'; -function memoize(fn) { - let val = undefined; - return function () { - if (val === undefined) { - val = fn(); - } - return val; - } -} - function notes(form) { const strings = ['string1', 'string2', 'string3', 'string4', 'string5', 'string6']; const formData = new FormData(form); @@ -19,15 +9,20 @@ function notes(form) { return strings.map((klass) => fretToNote(form, klass, formData.get(klass))); } -function onSave(form) { - console.debug('we done saved', form, notes(form)); -} - function init() { - console.debug('App#init', this); + console.debug('init()', this); Fretboard.register(); KeyPicker.register(); History.register(); + + // todo: maybe just attach the listener to document? + document.querySelectorAll(Fretboard.name).forEach(f => { + f.addEventListener(f.saveEvent, e => { + document.querySelectorAll(History.name).forEach(h => { + h.add(e.detail); + }); + }); + }); } document.addEventListener('DOMContentLoaded', init); -- cgit v1.3