immer.setAutoFreeze(false);// needed for high-frequency updated values, like onkeyup->note.temp_text; only once 'save' is called will it produce a new immutable state tree
@ -22,25 +24,132 @@ if(bin_id === ''){
}
// the actual loading from server is done later, after store and dispatch are defined
/* Integrates a database row from the server into the local store: */
constintegrate=function(s,model_object){
constid=model_object.id;
s.db[id]=s.db[id]||{ref_count:0,model:null};
s.db[id].model=model_object;
};
consti=integrate;
/* integrates a list of model objects, as if 'integrate' were called on each element. */
constintegrateAll=function(s,model_objects){
model_objects.forEach(mo=>{
integrate(s,mo);
});
};
/* Register a reference-by-id: */
constref=function(s,o,key,new_model_id){
constold_model_id=o[key];
s.db[new_model_id].ref_count++;
if(old_model_id&&s.db[old_model_id]){
s.db[old_model_id].ref_count--;
if(s.db[old_model_id].ref_count===0){
deletes.db[old_model_id];
}
}
// this needs to come after the above 'if' statement:
o[key]=new_model_id;
};
/* Register references in-bulk: */
/* o[key] refers to an array-of-ids */
constrefAll=function(s,o,key,new_model_ids){
constold_model_ids=o[key];
// ref the new refs:
o[key]=new_model_ids;
new_model_ids.forEach(new_model_id=>{
s.db[new_model_id].ref_count++;
});
// de-ref the existing refs, deleting no-longer-referred-to models:
old_model_ids.forEach(old_model_id=>{
s.db[old_model_id].ref_count--;
// if this is the last reference, delete it from the store:
'update-note-text':(s,{id,text})=>{constnote_s=s.notes.find(n=>n.note.id===id);note_s.note.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-text':(s,{id,text})=>{constnote_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
// TODO: replace `===` with a constant-time comparison function to prevent timing attacks; or better, store passwords as salted hashes and use `===` on that: