예제 #1
0
 public ValueBindingExpression(CompiledBindingExpression.BindingDelegate func, string javascript = null, CompiledBindingExpression.BindingUpdateDelegate updateFunc = null)
     : base(new CompiledBindingExpression()
     {
         Delegate = func,
         Javascript = javascript,
         UpdateDelegate = updateFunc
     })
 {
 }
예제 #2
0
 /// <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;
 }
예제 #3
0
 /// <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 + "}})";
		}
예제 #5
0
        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)
 {
 }
예제 #7
0
 public StaticCommandBindingExpression(CompiledBindingExpression expression)
     : base(expression)
 {
 }
 public ControlCommandBindingExpression(CompiledBindingExpression expression)
     : base(expression)
 {
 }
예제 #9
0
 /// <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)
 {
 }
예제 #12
0
 public CommandBindingExpression(CompiledBindingExpression.BindingDelegate command, string id)
     : base(new CompiledBindingExpression { Delegate = command, Id = id, Javascript = $"dotvvm.postbackScript('{ id }')" })
 { }
예제 #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ResourceBindingExpression"/> class.
 /// </summary>
 public ResourceBindingExpression(CompiledBindingExpression expression) : base(expression)
 {
 }
예제 #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ValueBindingExpression"/> class.
 /// </summary>
 public ValueBindingExpression(CompiledBindingExpression expression)
     : base(expression)
 {
 }
예제 #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ResourceBindingExpression"/> class.
 /// </summary>
 public ResourceBindingExpression(CompiledBindingExpression expression) : base(expression)
 {
 }
 public StaticCommandBindingExpression(CompiledBindingExpression expression)
     : base(expression)
 { }
 public ControlPropertyBindingExpression(CompiledBindingExpression expression)
     : base(expression)
 {
 }