示例#1
0
 public static KnockoutProxy Generate(IBindableToJs viewModel)
 {
     return(new KnockoutProxy(viewModel.Name,
                              PrimitiveObservablesGenerator.GetPropertiesAsObservables(viewModel),
                              SimpleMethodsGenerator.GetMethodProxies(viewModel),
                              ObservableArraysGenerator.GetCollectionsAsObservables(viewModel)));
 }
 public static KnockoutProxy Generate(IBindableToJs viewModel)
 {
     return new KnockoutProxy(viewModel.Name,  
         PrimitiveObservablesGenerator.GetPropertiesAsObservables(viewModel), 
         SimpleMethodsGenerator.GetMethodProxies(viewModel), 
         ObservableArraysGenerator.GetCollectionsAsObservables(viewModel));
 }
        internal static string GetPropertiesAsObservables(IBindableToJs javaScript)
        {
            var observableProperties = javaScript.GetType().GetProperties().Where(IsObservableWeSupport);

            var observableDefinitions = Enumerable.Select(observableProperties, x => CreateObservableFunction(x.Name, javaScript.Name));

            return String.Join(Environment.NewLine, observableDefinitions);
        }
        internal static string GetCollectionsAsObservables(IBindableToJs viewModel)
        {
            var observableCollections = viewModel.GetType().ObservableCollectionProperties();

            var observableArrays = observableCollections.Select(info => CreateObservableArrayWithListener(info.Name, viewModel.Name, info.GetValue(viewModel, null))).ToList();

            return String.Join(Environment.NewLine, observableArrays);
        }
示例#5
0
        internal static string GetPropertiesAsObservables(IBindableToJs javaScript)
        {
            var observableProperties = javaScript.GetType().GetProperties().Where(IsObservableWeSupport);

            var observableDefinitions = Enumerable.Select(observableProperties, x => CreateObservableFunction(x.Name, javaScript.Name));

            return(String.Join(Environment.NewLine, observableDefinitions));
        }
示例#6
0
        internal static string GetCollectionsAsObservables(IBindableToJs viewModel)
        {
            var observableCollections = viewModel.GetType().ObservableCollectionProperties();

            var observableArrays = observableCollections.Select(info => CreateObservableArrayWithListener(info.Name, viewModel.Name, info.GetValue(viewModel, null))).ToList();

            return(String.Join(Environment.NewLine, observableArrays));
        }
示例#7
0
        private static void UpdateSimpleObservable(IBindableToJs viewModel, string observableName, Action <string> javascriptExecutor)
        {
            var newValueGetter = string.Format("{0}.get_{1}()", viewModel.Name, observableName);

            var updateObservable = string.Format("{0}.{1}({2})", s_Proxies[viewModel].ViewModelInstanceName, observableName, newValueGetter);

            javascriptExecutor(updateObservable);
        }
示例#8
0
        private static void UpdateKnockoutCollection(IBindableToJs viewModel, string observableName, IEnumerable <object> values, Action <string> javascriptExecutor)
        {
            var updateObservable = string.Format(@"
                                                  var underlyingArray = {0}.{1}();

                                                  underlyingArray.length = 0;

                                                  ko.utils.arrayPushAll(underlyingArray, {2});

                                                  {0}.{1}.valueHasMutated();
            
            ", s_Proxies[viewModel].ViewModelInstanceName, observableName, values.ToJson());

            javascriptExecutor(updateObservable);
        }
        internal static string GetMethodProxies(IBindableToJs toBind)
        {
            var methodInfos = toBind.GetType().GetMethods().Where(IsReturnTypeWeSupport);

            return(String.Join(Environment.NewLine, methodInfos.Select(info => CreateMethodProxy(toBind.Name, info.Name))));
        }
        internal static string GetMethodProxies(IBindableToJs toBind)
        {
            var methodInfos = toBind.GetType().GetMethods().Where(IsReturnTypeWeSupport);

            return String.Join(Environment.NewLine, methodInfos.Select(info => CreateMethodProxy(toBind.Name, info.Name)));
        }