Skip to content

Commit

Permalink
dueLog(): Handle log line element replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
surol committed Aug 31, 2021
1 parent 9b093c6 commit 0dcf7da
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
10 changes: 10 additions & 0 deletions src/loggable/due-log.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ describe('dueLog', () => {
it('does not alter raw value', () => {
expect(dueLog({ line: [1, 2, 'test'] })).toEqual({ line: [1, 2, 'test'], index: 3 });
});
it('handles log line element replacement', () => {

const toLog: Loggable = {
toLog(target) {
target.line[target.index] = logAsTest;
},
};

expect(dueLog({ line: [1, toLog, 2] })).toEqual({ line: [1, 'test', 2], index: 3 });
});
it('replaces log line element by loggable representation', () => {
expect(dueLog({ line: [1, logAsTest, 2] })).toEqual({ line: [1, 'test', 2], index: 3 });
});
Expand Down
2 changes: 1 addition & 1 deletion src/loggable/due-log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export function dueLog<TTarget extends DueLog.Target>(

if (due.index !== index) {
due.index = Math.max(due.index, 0);
} else if (due.line === line) {
} else if (due.line === line && line[index] === value) {
if (toLog === undefined || toLog === value) {
++due.index;
} else if (!isLoggable(toLog) && Array.isArray(toLog)) {
Expand Down
6 changes: 3 additions & 3 deletions src/loggable/loggable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ export interface Loggable<TTarget extends DueLog.Target = DueLog.Target> {
*
* The method call results interpreted as following:
*
* 1. If the method replaced the {@link DueLog.line log line} or updated the next element's {@link DueLog.index
* index}, then the returned value is ignored, and the new log line processing continues from the new element
* index.
* 1. If the method replaced the {@link DueLog.line log line} or currently processed element, or updated the next
* element's {@link DueLog.index index}, then the returned value is ignored, and the new log line processing
* continues from the new element index.
*
* 2. If the returned value is `undefined` or the same as `this`, then the log line processing continues from the next
* element.
Expand Down

0 comments on commit 0dcf7da

Please sign in to comment.