BackgroundClass Expression

Expressions are an essential part of Mahalo. They consist of anexpression string and a scope in which they will be executed.With their ability to watch for changes in their evaluatedresult expressions are a very powerful feature of the framework.

That beeing said most of their magic is happening behind the scenesand their implicit usage should be rare. For common use casesMahalo provides higher level access to them. Most notably ina Template.

Syntax

The syntax of Mahalo expressions is similar JavaScript itself.However there are the following differences.

Variables

You cannot access any global or local variables since expressionsare evaluated in a scope. So every identifier will be treated asa property of the expressions scope.

To go deeper into an object you can of course use the dot andbracket syntax just like in JavaScript. In case the propertyof the scope you're looking for contains characters that arenot allowed in valid JavaScript identifiers you can start with thebracket syntax prefixed with a dot.

${ .['§property'] }

Comparisons

All comparisons will be strictly equal on evaluation but the syntaxonly knows loose operators (==, !=, <=, >=, <, >).

Filters

You can use the | symbol to apply a filter to the expression leftto it. See the filters A list of available

Unallowed stuff

Statements like if, for, while, try are not allowed.Also there are no declarations or assignments of any kind possible inMahalo expression. You can only use single line statements. The ;symbol is also invalid.

alias

{ default } from mahalo/expression/index

Hierarchy

  • Expression

Index

Constructors

constructor

  • new Expression(expression: string, scope: Object): Expression
  • Parameters
    • expression: string
    • scope: Object
    Returns Expression

Properties

callbacks

callbacks:Set<Function>

A set of callbacks that are eexcuted when the result of theexpression changed.

interceptor

interceptor:Function

The interceptor that will be used.

parser

parser:Parser

The parser for the expression string.

scope

scope:Object

The scope that is used for evaluation.

value

value:any

The result of evaluating the expression.

Methods

compile

  • compile(): any
  • Evaluates the expression.

    Returns any

unwatch

  • unwatch(callback?: Function): void
  • Removes a previously added callback from the expression.

    Parameters
    • Optional callback: Function
    Returns void

watch

  • watch(callback: Function): void
  • Adds a callback that is executed when the expression'sresult has changed.

    Parameters
    • callback: Function
    Returns void