mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
Added comments for some regex used in bindings.
This commit is contained in:
@ -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 module bindingConstants {
|
||||||
export var sourceProperty = "sourceProperty";
|
export var sourceProperty = "sourceProperty";
|
||||||
|
@ -21,7 +21,12 @@ function onBindingContextChanged(data: dependencyObservable.PropertyChangeData)
|
|||||||
}
|
}
|
||||||
|
|
||||||
var contextKey = "context";
|
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*\]/;
|
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 parentsRegex = /\$parents\s*\[\s*(['"]*)\w*\1\s*\]/g;
|
||||||
var bc = bindingBuilder.bindingConstants;
|
var bc = bindingBuilder.bindingConstants;
|
||||||
|
|
||||||
@ -201,6 +206,12 @@ export class Binding {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private prepareExpressionForUpdate(): string {
|
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 escapeRegex = /[-\/\\^$*+?.()|[\]{}]/g;
|
||||||
var escapedSourceProperty = this.options.sourceProperty.replace(escapeRegex, '\\$&');
|
var escapedSourceProperty = this.options.sourceProperty.replace(escapeRegex, '\\$&');
|
||||||
var expRegex = new RegExp(escapedSourceProperty, 'g');
|
var expRegex = new RegExp(escapedSourceProperty, 'g');
|
||||||
|
Reference in New Issue
Block a user