Permalink
Browse files

Knockout mapping bindings to support arrays (via @elkdanger)

  • Loading branch information...
1 parent dee896a commit 8dff04f76229e170f6545424ffe3db76f26b70ae @nikhilk committed Nov 4, 2012
@@ -44,6 +44,8 @@
<ItemGroup>
<Compile Include="BindingContext.cs" />
<Compile Include="CompareResult.cs" />
+ <Compile Include="KnockoutMappingArrayCreateOptions.cs" />
+ <Compile Include="KnockoutMappingArraySpecification.cs" />
<Compile Include="KnockoutMappingCreateOptions.cs" />
<Compile Include="KnockoutMappingUpdateOptions.cs" />
<Compile Include="DependentObservableOptions.cs" />
@@ -43,6 +43,19 @@ public sealed class KnockoutMapping {
return default(TModel);
}
+ /// <summary>
+ /// Creates a model array from the specified JSON string and a
+ /// custom mapping.
+ /// </summary>
+ /// <typeparam name="TModel">The type of the model.</typeparam>
+ /// <param name="jsonData">The JSON data.</param>
+ /// <param name="mapping">The mapping rules to apply.</param>
+ /// <returns>A new instance of the model.</returns>
+ [ScriptName("fromJSON")]
+ public ObservableArray<TModel> ModelFromJson<TModel>(string jsonData, KnockoutMappingArraySpecification mapping) {
+ return null;
+ }
+
/// <summary>
/// Creates a model instance from the specified script object.
/// </summary>
@@ -67,6 +80,19 @@ public sealed class KnockoutMapping {
return default(TModel);
}
+ /// <summary>
+ /// Creates a model array from the specified script object and a
+ /// custom mapping.
+ /// </summary>
+ /// <typeparam name="TModel">The type of the model.</typeparam>
+ /// <param name="data">The vanilla script object.</param>
+ /// <param name="mapping">The mapping rules to apply.</param>
+ /// <returns>A new instance of the model.</returns>
+ [ScriptName("fromJS")]
+ public Observable<TModel> ModelFromObject<TModel>(object data, KnockoutMappingArraySpecification<TModel> mapping) {
+ return null;
+ }
+
/// <summary>
/// Updates a model instance from the specified script object and a
/// custom mapping.
@@ -81,6 +107,20 @@ public sealed class KnockoutMapping {
return default(TModel);
}
+ /// <summary>
+ /// Creates a model array from the specified script object and a
+ /// custom mapping.
+ /// </summary>
+ /// <typeparam name="TModel">The type of the model.</typeparam>
+ /// <param name="data">The vanilla script object.</param>
+ /// <param name="mapping">The mapping rules to apply.</param>
+ /// <param name="target">The mapping rules to apply.</param>
+ /// <returns>A new instance of the model.</returns>
+ [ScriptName("fromJS")]
+ public Observable<TModel> ModelFromObject<TModel>(object data, KnockoutMappingArraySpecification<TModel> mapping, ObservableArray<TModel> target) {
+ return null;
+ }
+
/// <summary>
/// Unwraps the given view model
/// </summary>
@@ -0,0 +1,37 @@
+// KnockoutMappingArrayCreateOptions.cs
+// Script#/Libraries/Knockout
+// This source code is subject to terms and conditions of the Apache License, Version 2.0.
+//
+
+using System;
+using System.Runtime.CompilerServices;
+
+namespace KnockoutApi {
+
+ [IgnoreNamespace]
+ [Imported]
+ [ScriptName("Object")]
+ public sealed class KnockoutMappingArrayCreateOptions {
+
+ [IntrinsicProperty]
+ public object Data {
+ get {
+ return null;
+ }
+ }
+
+ [IntrinsicProperty]
+ public object Parent {
+ get {
+ return null;
+ }
+ }
+
+ [IntrinsicProperty]
+ public object Skip {
+ get {
+ return null;
+ }
+ }
+ }
+}
@@ -0,0 +1,43 @@
+// KnockoutMappingArraySpecification.cs
+// Script#/Libraries/Knockout
+// This source code is subject to terms and conditions of the Apache License, Version 2.0.
+//
+
+using System;
+using System.Runtime.CompilerServices;
+
+namespace KnockoutApi {
+
+ [IgnoreNamespace]
+ [Imported]
+ [ScriptName("Object")]
+ public abstract class KnockoutMappingArraySpecification {
+
+ internal KnockoutMappingArraySpecification() {
+ }
+ }
+
+ [IgnoreNamespace]
+ [Imported]
+ [ScriptName("Object")]
+ public sealed class KnockoutMappingArraySpecification<TModel> : KnockoutMappingArraySpecification {
+
+ [IntrinsicProperty]
+ public Func<KnockoutMappingArrayCreateOptions, TModel> Create {
+ get {
+ return null;
+ }
+ set {
+ }
+ }
+
+ [IntrinsicProperty]
+ public Func<TModel, object> Key {
+ get {
+ return null;
+ }
+ set {
+ }
+ }
+ }
+}

0 comments on commit 8dff04f

Please sign in to comment.