-
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.
Merge branch 'refs/heads/feat/disabled-sections'
- Loading branch information
Showing
8 changed files
with
90 additions
and
2 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import {Pipe, PipeTransform} from '@angular/core'; | ||
import {ExpressionService} from '../services/expression.service'; | ||
|
||
@Pipe({ | ||
name: 'eval', | ||
pure: true, | ||
}) | ||
export class EvalPipe implements PipeTransform { | ||
constructor( | ||
private expressionService: ExpressionService, | ||
) { | ||
} | ||
|
||
transform(expression: string, context?: Record<string, any>): Promise<any> { | ||
return this.expressionService.eval(expression, context); | ||
} | ||
} |
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,28 @@ | ||
import {Injectable} from '@angular/core'; | ||
import {compile, Jexl} from 'jexl'; | ||
import Expression from 'jexl/Expression'; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class ExpressionService { | ||
private jexl = new Jexl(); | ||
private compiledExpressions = new Map<string, Expression>; | ||
|
||
evalSync(expression: string, context?: Record<string, any>): any { | ||
return this.compile(expression).evalSync(context); | ||
} | ||
|
||
eval(expression: string, context?: Record<string, any>): Promise<any> { | ||
return this.compile(expression).eval(context); | ||
} | ||
|
||
private compile(expression: string): Expression { | ||
let compiledExpression = this.compiledExpressions.get(expression); | ||
if (!compiledExpression) { | ||
compiledExpression = this.jexl.compile(expression); | ||
this.compiledExpressions.set(expression, compiledExpression); | ||
} | ||
return compiledExpression; | ||
} | ||
} |
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