mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-30 01:32:44 +00:00
Add model and add event listeners
This commit is contained in:
26
src/model/Path.ts
Normal file
26
src/model/Path.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
|
||||
type PathElement = (string | number)
|
||||
|
||||
export class Path {
|
||||
private arr: PathElement[]
|
||||
|
||||
constructor(arr?: PathElement[]) {
|
||||
this.arr = arr || []
|
||||
}
|
||||
|
||||
last(): PathElement {
|
||||
return this.arr[this.arr.length - 1]
|
||||
}
|
||||
|
||||
pop(): Path {
|
||||
return new Path(this.arr.slice(0, -1))
|
||||
}
|
||||
|
||||
push(element: PathElement): Path {
|
||||
return new Path([...this.arr, element])
|
||||
}
|
||||
|
||||
copy(): Path {
|
||||
return new Path([...this.arr])
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user