Skip to content

Instantly share code, notes, and snippets.

@anitaa1990
Last active November 30, 2024 16:41
Show Gist options
  • Select an option

  • Save anitaa1990/6d91bc2cf286f6a05e42388ea217dbd1 to your computer and use it in GitHub Desktop.

Select an option

Save anitaa1990/6d91bc2cf286f6a05e42388ea217dbd1 to your computer and use it in GitHub Desktop.
/**
* A sealed class representing all possible user actions (via intents).
* This helps to encapsulate and categorize user inputs in a type-safe and maintainable way,
* making it easier to handle these actions in a centralized manner (e.g., in a ViewModel).
* By using a sealed class for intents, MVI ensures that each possible user interaction is
* explicitly defined, making it easier to manage different actions in a structured way.
*/
sealed class NoteIntent {
/** Represents the intent to load a list of all notes. */
object LoadNotes : NoteIntent()
/** Represents the intent to load a specific note, possibly by ID. */
object LoadNote : NoteIntent()
/**
* Represents the intent to add a new note or save changes to an existing note.
* The exact behavior depends on the application context (e.g., whether editing or creating).
*/
data object AddOrSaveNote : NoteIntent()
/**
* Represents the intent to update the title of a note.
* @param title The new title for the note.
*/
data class UpdateNoteTitle(val title: String) : NoteIntent()
/**
* Represents the intent to update the description of a note.
* @param description The new description for the note.
*/
data class UpdateNoteDescription(val description: String) : NoteIntent()
/**
* Represents the intent to delete a note.
* @param note The note to be deleted.
*/
data class DeleteNote(val note: Note) : NoteIntent()
/**
* Represents the intent triggered when a note is clicked or opened.
* @param note The note that was clicked or selected.
*/
data class OpenNoteClicked(val note: Note) : NoteIntent()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment