Write

Summary

Entry

Lifecycle

Basic

writeNote {
	// see [[Write|dendron://dendron.docs/pkg.dendron-engine.t.engine.ref.write#^jP4rwHq1mdtd]]
  @store.writeNote
	// see [[Init|dendron://dendron.docs/pkg.dendron-engine.t.engine.ref.refresh#init]]
  @refreshNote
}
writeNote(note) {
  maybeNote = getNote(note.fname)

  shouldUpdate := note
  changed = []

  if shouldUpdate:
    note = {...maybeNote, ...note}
  else:
    changed = @_writeNewNote(note)

  // apply any schemas as needed
  schemaMatch = SchemaUtils.match(note)

  // apply any hooks as needed
  ...

  // write note to disk
  note2File(note)

  // schema matching logic
  ...

  // if any other notes were affected, apply changes here
  // see [[../packages/engine-server/src/drivers/file/storev2.ts#^change]]
  ...

}

_writeNewNote(note, existingNote?) {

  if existingNote @replacePrevNoteWithNewNote(note, existingNote)

  // we might need to add parents to this note
  changed = addParent(note)
  return changed
}

Update Only

Fast Mode

Writing in fast mode means without indexing existing notes. Some notable differences:

  • getNote calls are done from disk instead of from memory
  • when calling _writeNewNote, we don't change parents or children

Reference

Reference

Cook

Past Tasks