Class MistakeManager

Stores and manages all Mistakes. Start by using addMistake to add a Mistake to a CategoryNames.

Hierarchy

  • MistakeManager

Constructors

Properties

categoryMistakes: MistakeCategoryMap

A MistakeCategoryMap containing all Mistakes available by their categories (CategoryNames).

mistakes: Mistake[] = []

An Array containing all Mistakes (in all MistakeCategorys), sorted by their Mistake#orderIDs.

uiManager: undefined | UIManager = undefined

Methods

  • Generates a new GrammleID for the given category with the new highest ID number for that category.

    Returns

    the new GrammleID

    Parameters

    Returns GrammleID

  • Generates a YAML file containing the Mistakes, including the user's changes, and lets the user save it.

    Returns

    true if the file was generated successfully

    Returns true

  • Returns a new draft Mistake with the given category and a new GrammleID, by calling #generateGrammleID, and without any other fields set.

    This method is supposed to be called for creating a new Mistake in the UI.

    Info: The UID is optional and will only be set if it is valid.

    Returns

    the new Mistake

    Parameters

    Returns Mistake

  • Returns the highest ID number in the given category, starting at 1. Returns 0 if no mistakes are in the category.

    Returns

    the ID number

    Parameters

    Returns number

  • Returns the given Mistake's index in the array of the CategoryNames. Partly written by GitHub Copilot.

    Returns

    Zero-based index of the Mistake in the CategoryNames's array. Return value -1 means “not found”.

    Parameters

    Returns number

  • Returns Mistake[]

  • Returns a plain object containing the Mistakes as an array under the key articles.

    Returns

    deep copies of the Mistakes as a plain object

    Returns Object

  • Updates the overall #mistakes Array by merging all Mistakes from the #categoryMistakes map.

    Returns

    true if the Mistakes were merged successfully, false otherwise

    Returns boolean

  • Converts the Mistakes Array to a plain object.

    Returns

    a deep copy of the Mistakes as a plain object

    Returns Object

  • Creates a new #categoryMistakes map from scratch by adding all Mistakes from #mistakes to their respective categories.

    Returns

    true if the #categoryMistakes map was re-created successfully

    Returns true

  • Parameters

    Returns void

  • Parameters

    Returns void

  • TL;DR

    Tries to find an existing Mistake with the same Mistake#fields#uid (or Mistake#fields#id if unsuccessful) as the given mistake, and replaces it, if found. Otherwise, the given mistake is added as a new one.

    Cases

    § 1: new UID, new ID

    There's nothing to replace, wherefore the given mistake is added as a new Mistake by calling #addMistake.
    Returns CREATE.

    § 2: new UID, existing ID

    An entirely new Mistake was added that will replace an existing one. Therefore, the Mistake with the same Mistake#fields#id is replaced in-place with the given mistake.
    Returns EDIT.

    § 3: existing UID, new ID

    An existing Mistake gets a new Mistake#fields#id. Therefore, the Mistake with the same Mistake#fields#uid is deleted, and the given mistake is added as a new Mistake by calling #addMistake.
    Returns EDIT.

    § 4: existing UID, existing ID

    An existing Mistake replaces another existing one. Therefore, the Mistake with the same Mistake#fields#uid is deleted, and the Mistake with the same Mistake#fields#id is replaced in-place with the given mistake.
    Returns EDIT.

    Returns

    the EditMode that was used to update the Mistake

    • EditMode.EDIT: A matching Mistake was found and replaced successfully with the given mistake.
    • EditMode.CREATE: No matching Mistake was found. The given mistake was added as a new one successfully.

    Throws

    IllegalArgumentError

    • if the given mistake is invalid in terms of Mistake#validate or
    • if it could not be added.

    Parameters

    Returns IllegalArgumentError | EditMode

  • Private

    Checks whether the given index is a non-negative finite integer.

    Returns

    true if the given index is a non-negative finite integer, false otherwise

    Parameters

    • index: number

      the index to check

    Returns boolean

Generated using TypeDoc