public ValueBindingExpression(CompiledBindingExpression.BindingDelegate func, string javascript = null, CompiledBindingExpression.BindingUpdateDelegate updateFunc = null) : base(new CompiledBindingExpression() { Delegate = func, Javascript = javascript, UpdateDelegate = updateFunc }) { }
/// <summary> /// Initializes a new instance of the <see cref="BindingExpression"/> class. /// </summary> public BindingExpression(CompiledBindingExpression compiledBinding) : this() { OriginalString = compiledBinding.OriginalString; Javascript = compiledBinding.Javascript; ExpressionTree = compiledBinding.Expression; Delegate = compiledBinding.Delegate; UpdateDelegate = compiledBinding.UpdateDelegate; BindingId = compiledBinding.Id; ActionFilters = compiledBinding.ActionFilters; }
public override string CompileToJavascript(ResolvedBinding binding, CompiledBindingExpression compiledExpression) { var expression = binding.GetExpression(); var visitor = new ExtractExpressionVisitor(ex => ex.NodeType == ExpressionType.Call); var rootCallback = visitor.Visit(expression); var js = SouldCompileCallback(rootCallback) ? "resultPromise.resolve(" + JavascriptTranslator.CompileToJavascript(rootCallback, binding.DataContextTypeStack) + ")" : null; foreach (var param in visitor.ParameterOrder.Reverse<ParameterExpression>()) { if (js == null) js = $"resultPromise.resolve({param.Name})"; var callback = $"function({param.Name}){{{js}}}"; var method = visitor.Replaced[param] as MethodCallExpression; js = CompileMethodCall(method, binding.DataContextTypeStack, callback); } return "var $context = ko.contextFor(this);var sender = this;var resultPromise = new DotvvmPromise();(function(i_pageArea){with($context){" + js + "}})"; }
public virtual string CompileToJavascript(ResolvedBinding binding, CompiledBindingExpression expression) { var javascript = JavascriptTranslator.CompileToJavascript(binding.GetExpression(), binding.DataContextTypeStack); if (javascript == "$data") { javascript = "$rawData"; } else if (javascript.StartsWith("$data.", StringComparison.Ordinal)) { javascript = javascript.Substring("$data.".Length); } // do not produce try/eval on single properties if (javascript.Contains(".") || javascript.Contains("(")) { return "dotvvm.evaluator.tryEval(function(){return " + javascript + "})"; } else { return javascript; } }
public ControlCommandBindingExpression(CompiledBindingExpression expression) : base(expression) { }
public StaticCommandBindingExpression(CompiledBindingExpression expression) : base(expression) { }
/// <summary> /// Initializes a new instance of the <see cref="ValueBindingExpression"/> class. /// </summary> public ValueBindingExpression(CompiledBindingExpression expression) : base(expression) { }
public override string CompileToJavascript(ResolvedBinding binding, CompiledBindingExpression expression) { return $"dotvvm.postbackScript({ JsonConvert.SerializeObject(expression.Id) })"; }
public ControlPropertyBindingExpression(CompiledBindingExpression expression) : base(expression) { }
public CommandBindingExpression(CompiledBindingExpression.BindingDelegate command, string id) : base(new CompiledBindingExpression { Delegate = command, Id = id, Javascript = $"dotvvm.postbackScript('{ id }')" }) { }
/// <summary> /// Initializes a new instance of the <see cref="ResourceBindingExpression"/> class. /// </summary> public ResourceBindingExpression(CompiledBindingExpression expression) : base(expression) { }