DevJoy.Session.History (DevJoy v2.0.0)
View SourceProvides functionality to work with the session history.
Since a history usually focuses on current and forward entries the order of entries is reversed i.e. that the history starts with forward entries and ends with the previous entries.
Summary
Functions
Handles the navigation back logic based on the current history entry.
Returns the current history entry.
Drops the forward history entries, the current history entry
and amount - 1 number of previous history entries.
It returns the current history entry after dropping the specified entries,
or nil if the history is empty or all entries have been dropped.
The forward/0 function is used to handle the navigation forward logic based on the current history entry.
Determines whether it's possible to navigate forward in the session history.
Determines whether it's possible to navigate back in the session history.
Updates the history based on the current history entry.
Functions
@spec back() :: DevJoy.Session.entry() | nil
Handles the navigation back logic based on the current history entry.
It considers the following scenarios:
- Returns
nilIf the history is empty. - Returns
nilif the current history entry is the last entry in the history and its index is 1 - Otherwise if the index of a current history entry is 1, increments the history index and returns the previous entry.
- Otherwise it decrements the index of the current history entry and returns this updated entry
Usage
# :ok = DevJoy.API.Storage.set_history([…])
current_entry = DevJoy.Session.History.back()
is_nil(current_entry) or is_tuple(current_entry) and tuple_size(current_entry) == 3
# => true@spec current_entry(true) :: DevJoy.Session.entry() | nil
@spec current_entry(false) :: DevJoy.API.Storage.history_entry() | nil
Returns the current history entry.
Usage
If drop_max_index parameter is set to true the max_index from the
history_entry is removed.
Defaults to true.
# :ok = DevJoy.API.Storage.set_history([…])
current_entry = DevJoy.Session.History.current_entry()
is_nil(current_entry) or is_tuple(current_entry) and tuple_size(current_entry) == 3
# => true
current_entry = DevJoy.Session.History.current_entry(false)
is_nil(current_entry) or is_tuple(current_entry) and tuple_size(current_entry) == 4
# => true@spec drop(non_neg_integer()) :: DevJoy.Session.entry() | nil
Drops the forward history entries, the current history entry
and amount - 1 number of previous history entries.
It returns the current history entry after dropping the specified entries,
or nil if the history is empty or all entries have been dropped.
Usage
# :ok = DevJoy.API.Storage.set_history([…])
current_entry = DevJoy.Session.History.drop()
is_nil(current_entry) or is_tuple(current_entry) and tuple_size(current_entry) == 3
# => true
# :ok = DevJoy.API.Storage.set_history([…])
current_entry = DevJoy.Session.History.drop(2)
is_nil(current_entry) or is_tuple(current_entry) and tuple_size(current_entry) == 3
# => true@spec forward() :: DevJoy.Session.entry() | nil
The forward/0 function is used to handle the navigation forward logic based on the current history entry.
It considers the following scenarios:
- Returns
nilif the current history entry's is the first in the history and its index is equal to the maximum index. - Otherwise if the index of a current history entry is equal to its maximum index, it decrements the index and returns the updated entry.
- Otherwise if the index of a current history entry is less than its maximum index, it increments the index and returns the updated entry.
- In all other cases, it returns
nil.
Usage
# :ok = DevJoy.API.Storage.set_history([…])
current_entry = DevJoy.Session.History.forward()
is_nil(current_entry) or is_tuple(current_entry) and tuple_size(current_entry) == 3
# => true@spec forwardable?() :: boolean()
Determines whether it's possible to navigate forward in the session history.
Returns false if the session history is empty.
Returns true if the index of the current entry
is less than the max_index or the history index is greater than 0.
Returns false otheriwse.
Usage
result = DevJoy.Session.History.forwardable?()
is_boolean(result)
# => true@spec reversible?() :: boolean()
Determines whether it's possible to navigate back in the session history.
Returns false if the session history is empty.
Returns true if the index of the current entry
is greater than 1 or if the current element is not the last one in the ssions history.
Returns false otheriwse.
Usage
result = DevJoy.Session.History.reversible?()
is_boolean(result)
# => true@spec update(DevJoy.Session.entry()) :: DevJoy.Session.entry()
Updates the history based on the current history entry.
If the current history entry has the same scene and part name as an existing entry, the function replaces the index of the existing entry and updates its maximum index to the maximum of the current entry's maximum index and the updated index, finally returning the updated entry.
If the current history entry has a different scene or part name, the function inserts a new history entry before the current entry and returns the new entry.
Usage
# :ok = DevJoy.API.Storage.set_history([…])
current_entry = DevJoy.Session.History.update({MyApp.MyScene, :part_name, 1})
is_tuple(current_entry) and tuple_size(current_entry) == 3
# => true