-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
78 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import asArray from 'asArray'; | ||
import last from 'last'; | ||
|
||
export function createCursor() { | ||
const storage: { cursor: number[] } = { | ||
cursor: [], | ||
}; | ||
|
||
function addLevel(): void { | ||
storage.cursor.push(0); | ||
} | ||
|
||
function removeLevel(): void { | ||
storage.cursor.pop(); | ||
} | ||
|
||
function cursorAt(): number { | ||
return last(storage.cursor); | ||
} | ||
|
||
function getCursor(): number[] { | ||
return asArray(storage.cursor); | ||
} | ||
|
||
function next(): number { | ||
storage.cursor[storage.cursor.length - 1]++; | ||
return last(storage.cursor); | ||
} | ||
|
||
function reset(): void { | ||
storage.cursor = [0]; | ||
} | ||
|
||
reset(); | ||
|
||
return { | ||
addLevel, | ||
cursorAt, | ||
getCursor, | ||
next, | ||
removeLevel, | ||
reset, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import ctx from 'ctx'; | ||
|
||
export function useTestCursorAt(): number { | ||
const context = ctx.useX(); | ||
return context.testCursor.cursorAt(); | ||
} | ||
|
||
export function moveTestCursorForward(): number { | ||
const context = ctx.useX(); | ||
return context.testCursor.next(); | ||
} | ||
|
||
export function addTestCursorLevel(): void { | ||
const context = ctx.useX(); | ||
context.testCursor.addLevel(); | ||
} | ||
|
||
export function removeTestCursorLevel(): void { | ||
const context = ctx.useX(); | ||
context.testCursor.removeLevel(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.