- Start support for auto-generated routes using UniversalPath
All checks were successful
continuous-integration/drone/push Build is passing

- Start support for custom view engine props & functions
- Start login template and namespace
This commit is contained in:
2021-06-29 01:44:07 -05:00
parent faa8a31102
commit cf6d14abca
9 changed files with 172 additions and 14 deletions

View File

@@ -8,6 +8,11 @@ export type PipeOperator<T, T2> = (subject: T) => T2
*/
export type ReflexivePipeOperator<T> = (subject: T) => T
/**
* A condition or condition-resolving function for pipe methods.
*/
export type PipeCondition<T> = boolean | ((subject: T) => boolean)
/**
* A class for writing chained/conditional operations in a data-flow manner.
*
@@ -79,8 +84,8 @@ export class Pipe<T> {
* @param check
* @param op
*/
when(check: boolean, op: ReflexivePipeOperator<T>): Pipe<T> {
if ( check ) {
when(check: PipeCondition<T>, op: ReflexivePipeOperator<T>): Pipe<T> {
if ( (typeof check === 'function' && check(this.subject)) || check ) {
return Pipe.wrap(op(this.subject))
}
@@ -94,8 +99,12 @@ export class Pipe<T> {
* @param check
* @param op
*/
unless(check: boolean, op: ReflexivePipeOperator<T>): Pipe<T> {
return this.when(!check, op)
unless(check: PipeCondition<T>, op: ReflexivePipeOperator<T>): Pipe<T> {
if ( (typeof check === 'function' && check(this.subject)) || check ) {
return this
}
return Pipe.wrap(op(this.subject))
}
/**
@@ -103,7 +112,7 @@ export class Pipe<T> {
* @param check
* @param op
*/
whenNot(check: boolean, op: ReflexivePipeOperator<T>): Pipe<T> {
whenNot(check: PipeCondition<T>, op: ReflexivePipeOperator<T>): Pipe<T> {
return this.unless(check, op)
}