From cff1e8f891fc65eb29b0ac882e7b58e4888e0f7a Mon Sep 17 00:00:00 2001 From: Nedyalko Nikolov Date: Wed, 1 Jul 2015 10:24:02 +0300 Subject: [PATCH] Added comments for some regex used in bindings. --- ui/builder/binding-builder.ts | 3 ++- ui/core/bindable.ts | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/ui/builder/binding-builder.ts b/ui/builder/binding-builder.ts index c5e828839..39ccbcf3e 100644 --- a/ui/builder/binding-builder.ts +++ b/ui/builder/binding-builder.ts @@ -1,4 +1,5 @@ -var expressionSymbolsRegex = /[ \+\-\*%\?:<>=!\|&\(\)\[\]^~]/; +// regex that contains all symbols applicable for expression used to AI detect an expression. +var expressionSymbolsRegex = /[ \+\-\*%\?:<>=!\|&\(\)\[\]^~]/; export module bindingConstants { export var sourceProperty = "sourceProperty"; diff --git a/ui/core/bindable.ts b/ui/core/bindable.ts index 85249dcc1..1d4902180 100644 --- a/ui/core/bindable.ts +++ b/ui/core/bindable.ts @@ -21,7 +21,12 @@ function onBindingContextChanged(data: dependencyObservable.PropertyChangeData) } var contextKey = "context"; +// this regex is used to get parameters inside [] for example: +// from $parents['ListView'] will return 'ListView' +// from $parents[1] will return 1 var paramsRegex = /\[\s*(['"])*(\w*)\1\s*\]/; + +// this regex is used to search for all instaces of '$parents[]' within an expression var parentsRegex = /\$parents\s*\[\s*(['"]*)\w*\1\s*\]/g; var bc = bindingBuilder.bindingConstants; @@ -201,6 +206,12 @@ export class Binding { } private prepareExpressionForUpdate(): string { + // this regex is used to create a valid RegExp object from a string that has some special regex symbols like [,(,$ and so on. + // Basically this method replaces all matches of 'source property' in expression with '$newPropertyValue'. + // For example: with an expression similar to: + // text="{{ sourceProperty = $parents['ListView'].test, expression = $parents['ListView'].test + 2}}" + // update expression will be '$newPropertyValue + 2' + // then on expression execution the new value will be taken and target property will be updated with the value of the expression. var escapeRegex = /[-\/\\^$*+?.()|[\]{}]/g; var escapedSourceProperty = this.options.sourceProperty.replace(escapeRegex, '\\$&'); var expRegex = new RegExp(escapedSourceProperty, 'g');