-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add missing src/detail-route.mjs from template
- Loading branch information
Showing
1 changed file
with
58 additions
and
0 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,58 @@ | ||
import { ValueStoreRoute } from "./routes.mjs"; | ||
|
||
/** | ||
* Route to represent a slice of the masters list of values. | ||
* | ||
* @property {Route} master route holding the master records | ||
*/ | ||
export class DetailRoute extends ValueStoreRoute { | ||
/** | ||
* Route holding the list ov values | ||
* @return {Route} our master | ||
*/ | ||
get master() { | ||
return this.parent; | ||
} | ||
|
||
/** | ||
* @return {Promise<any>} 1st. entry | ||
*/ | ||
async first() { | ||
return this.master.value[0]; | ||
} | ||
|
||
/** | ||
* @return {any} last entry | ||
*/ | ||
async last() { | ||
return this.master.value[this.master.value.length - 1]; | ||
} | ||
|
||
/** | ||
* @return {any} previous value | ||
*/ | ||
async previous() { | ||
const i = this.master.value.indexOf(this.value); | ||
if (i > 0) { | ||
return this.master.value[i - 1]; | ||
} | ||
} | ||
|
||
/** | ||
* @return {Promise<any>} next value | ||
*/ | ||
async next() { | ||
const i = this.master.value.indexOf(this.value); | ||
if (i >= 0) { | ||
return this.master.value[i + 1]; | ||
} | ||
} | ||
|
||
async valueFor(transition) { | ||
for await (const value of this.master.iteratorFor(transition)) { | ||
if (this.isAcceptable(value, transition.params)) { | ||
return value; | ||
} | ||
} | ||
} | ||
} |