import {edit_handler, cancel_handler, text_change_handler, save_handler} from './handlers/Note.js'; function Note(vnode_init){ const {dispatch} = vnode_init.attrs; return { view: function(vnode){ const {note_state} = vnode.attrs; const {is_editing, is_focused, note} = note_state; if(is_editing){ return m('.note', [ m('textarea', {key: 'textarea', onchange: text_change_handler.bind(null, note_state, dispatch), oncreate: is_focused?({dom})=>{ dom.focus(); delete note_state.is_focused; }:null }, note_state.temp_text), m('.buttons', {key: 'editing-buttons'}, [ m('button', {key: 'cancel-button', onclick: cancel_handler.bind(null, note_state, dispatch) }, 'Cancel'), m('button', {key: 'save-button', onclick: save_handler.bind(null, note_state, dispatch) }, 'Save') ]) ]); } else{ return m('.note', [ m('.text', {key: 'text'}, note.text), m('.buttons', {key: 'viewing-buttons'}, [ m('button', {key: 'edit-button', onclick: edit_handler.bind(null, note_state, dispatch) }, 'Edit') ]) ]); } } }; } export default Note;