public static ParametrizedCode AddIndexerToViewModel(ParametrizedCode script, JsExpression indexer, bool unwrap = false) { return(indexerCode.AssignParameters(o => o == indexerTargetParameter ? new CodeParameterAssignment(script) : o == indexerExpressionParameter ? CodeParameterAssignment.FromExpression(indexer) : default(CodeParameterAssignment))); }
/// <summary> /// Get's Javascript code that can be executed inside knockout data-bind attribute. /// </summary> public static string FormatKnockoutScript(ParametrizedCode expression, ParametrizedCode contextVariable, ParametrizedCode dataVariable = null) { if (dataVariable == null) { dataVariable = new ParametrizedCode.Builder { contextVariable, ".$data" } }
/// <summary> /// Get's Javascript code that can be executed inside knockout data-bind attribute. /// </summary> public static string FormatKnockoutScript(ParametrizedCode expression, bool allowDataGlobal = true, int dataContextLevel = 0) { // TODO(exyi): more symbolic parameters return(AdjustKnockoutScriptContext(expression, dataContextLevel) .ToString(o => o == KnockoutContextParameter ? CodeParameterAssignment.FromIdentifier("$context", true) : o == KnockoutViewModelParameter ? CodeParameterAssignment.FromIdentifier("$data", allowDataGlobal) : o == CurrentIndexParameter ? CodeParameterAssignment.FromIdentifier("$index()") : throw new Exception())); }
/// <summary> /// Get's Javascript code that can be executed inside knockout data-bind attribute. /// </summary> public static string FormatKnockoutScript(ParametrizedCode expression, bool allowDataGlobal = true, int dataContextLevel = 0) { // TODO(exyi): more symbolic parameters var adjusted = AdjustKnockoutScriptContext(expression, dataContextLevel); if (allowDataGlobal) { return(adjusted.ToDefaultString()); } else { return(adjusted.ToString(o => o == KnockoutViewModelParameter ? CodeParameterAssignment.FromIdentifier("$data", allowDataGlobal) :
public static ParametrizedCode AdjustKnockoutScriptContext(ParametrizedCode expression, int dataContextLevel) { if (dataContextLevel == 0) { return(expression); } var(contextExpresion, dataExpression) = GetKnockoutContextParameters(dataContextLevel); var(context, data) = (CodeParameterAssignment.FromExpression(contextExpresion), CodeParameterAssignment.FromExpression(dataExpression)); return(expression.AssignParameters(o => o == KnockoutContextParameter ? context : o == KnockoutViewModelParameter ? data : default(CodeParameterAssignment) )); }
public static ParametrizedCode AddIndexerToViewModel(ParametrizedCode script, object index, bool unwrap = false) => AddIndexerToViewModel(script, new JsLiteral(index), unwrap);