@ -78,6 +78,11 @@ const refAll = function(s, o, key, new_model_ids){
This routine would need to be called for state . notes , which contains refs of the form : ` state.notes[n].note_id `
This routine would need to be called for state . notes , which contains refs of the form : ` state.notes[n].note_id `
* /
* /
// TODO: doesn't update anything that references the deleted record; results in dangling pointers:
const disintegrate = function ( s , id ) {
delete s . db [ id ] ;
} ;
function addToBinListIfLoggedIn ( state ) {
function addToBinListIfLoggedIn ( state ) {
const s = state ;
const s = state ;
// if user is logged in:
// if user is logged in:
@ -98,9 +103,10 @@ const reducer = handleActions({
'bin-loaded' : ( s , bin ) => { i ( s , bin ) ; ref ( s , s , 'bin_id' , bin . id ) ; s . temp _bin _name = bin . name ; } ,
'bin-loaded' : ( s , bin ) => { i ( s , bin ) ; ref ( s , s , 'bin_id' , bin . id ) ; s . temp _bin _name = bin . name ; } ,
'update-search-term' : ( s , search _term ) => { s . search _term = search _term ; } ,
'update-search-term' : ( s , search _term ) => { s . search _term = search _term ; } ,
'update-search-results' : ( s , _notes ) => { integrateAll ( s , s . notes , 'note_id' , _notes ) ; s . notes = _notes . map ( n => ( { is _editing : false , temp _text : '' , bin _id : s . bin _id , note _id : n . id } ) ) ; } ,
'update-search-results' : ( s , _notes ) => { integrateAll ( s , s . notes , 'note_id' , _notes ) ; s . notes = _notes . map ( n => ( { is _editing : false , temp _text : '' , bin _id : s . bin _id , note _id : n . id } ) ) ; } ,
'add-note' : ( s , { id , date } ) => { i ( s , { id : id , text : '' , modified : date } ) ; s . notes . unshift ( { is _editing : true , temp _text : '' , bin _id : s . bin _id , is _focused : true , note_id : id } ) ; } ,
'add-note' : ( s , { id , date } ) => { i ( s , { id : id , text : '' , modified : date } ) ; s . notes . unshift ( { is _editing : true , temp _text : '' , bin _id : s . bin _id , is _focused : true , is_new : true , note_id : id } ) ; } ,
'notes-loaded' : ( s , _notes ) => { integrateAll ( s , _notes ) ; s . notes = _notes . map ( n => ( { is _editing : false , temp _text : n . text , bin _id : s . bin _id , note _id : n . id } ) ) ; } ,
'notes-loaded' : ( s , _notes ) => { integrateAll ( s , _notes ) ; s . notes = _notes . map ( n => ( { is _editing : false , temp _text : n . text , bin _id : s . bin _id , note _id : n . id } ) ) ; } ,
'update-note-text' : ( s , { id , text } ) => { const note _s = s . notes . find ( n => n . note _id === id ) ; s . db [ note _s . note _id ] . model . text = text ; } , // updates underlying note text (i.e. the "model", not the app note_state) "in the background" (e.g. from a server-pushed update), regardless of whether it's being edited; "save" is a separate action, below
'immediately-cancel-note' : ( s , note _id ) => { disintegrate ( s , note _id ) ; s . notes . splice ( s . notes . findIndex ( n => n . note _id === note _id ) , 1 ) ; } ,
'update-note-text' : ( s , { id , text } ) => { const note _s = s . notes . find ( n => n . note _id === id ) ; note _s . is _new = false ; s . db [ note _s . note _id ] . model . text = text ; } , // updates underlying note text (i.e. the "model", not the app note_state) "in the background" (e.g. from a server-pushed update), regardless of whether it's being edited; "save" is a separate action, below
'update-note-editing' : ( s , { id , is _editing } ) => { const note _s = s . notes . find ( n => n . note _id === id ) ; note _s . is _editing = is _editing ; note _s . temp _text = s . db [ note _s . note _id ] . model . text ; } ,
'update-note-editing' : ( s , { id , is _editing } ) => { const note _s = s . notes . find ( n => n . note _id === id ) ; note _s . is _editing = is _editing ; note _s . temp _text = s . db [ note _s . note _id ] . model . text ; } ,
'save-note-edit' : ( s , { id , text } ) => { const note _s = s . notes . find ( n => n . note _id === id ) ; s . db [ note _s . note _id ] . model . text = text ; note _s . temp _text = text ; note _s . is _editing = false ; } ,
'save-note-edit' : ( s , { id , text } ) => { const note _s = s . notes . find ( n => n . note _id === id ) ; s . db [ note _s . note _id ] . model . text = text ; note _s . temp _text = text ; note _s . is _editing = false ; } ,
'update-sorting' : ( s , sorting ) => { s . sorting = sorting ; } ,
'update-sorting' : ( s , sorting ) => { s . sorting = sorting ; } ,