Skip to content

Commit

Permalink
add missing src/detail-route.mjs from template
Browse files Browse the repository at this point in the history
  • Loading branch information
arlac77 committed Jun 20, 2024
1 parent ee97c55 commit 3071121
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions src/detail-route.mjs
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;
}
}
}
}

0 comments on commit 3071121

Please sign in to comment.