locked
requireSupportedForProcessing Error Even When Defining Class With WinJS.Class.define RRS feed

  • Question

  • According to the documentation on the WinJS.Utilities.requireSupportedForProcessing function, functions defined in classes defined with WinJS.Class.define automatically get marked for support for binding processing. That being said, why is the following code still throwing the error:

    WinJS.Utilities.requireSupportedForProcessing: Value is not supported within a declarative processing context, if you want it to be supported mark it using WinJS.Utilities.markSupportedForProcessing.

     HTML:

    <section aria-label="Main content" role="main" data-win-bindsource="Application.Pages.Home.ViewModel">
        <div data-win-bind="innerText:number"></div>
        <button data-win-bind="click:incrementNumber">+</button>
    </section>

    JavaScript:

    (function () {
        "use strict";
    
        var ViewModel = WinJS.Namespace.define("Application.Pages.Home", {
            ViewModel : WinJS.Class.define(function(){
                this._number = 0;
            }, {
                incrementNumber: function () {
                    this._number++;
                }
            }, {
                // no statics
            })
        });
    
        var _vm = new Application.Pages.Home.ViewModel();
    
        WinJS.UI.Pages.define("/pages/home/home.html", {
            ready: function (element, options) {
                WinJS.Binding.processAll(document.body, _vm);
            }
        });
    })();

    Am I declaring the class incorrectly somehow?


    Thursday, August 23, 2012 10:27 PM

Answers

  • The wording is a little confusing.  Not all functions in the NS define are set.  Only the constructor of your mixin.  I debugged this and you can see that indeed that it is not set.  Only the constructor is marked, not the individual functions.

    -Jeff


    Jeff Sanders (MSFT)

    Monday, August 27, 2012 7:21 PM
    Moderator

All replies

  • Are you using incrementNumber somewhere?

    WinJS.Class.define only marks the constructor function as supported for processing so that you can use that class in a data-win-control attribute.

    If you have functions you want to use in data binding or access in the data-win-options record you need to mark them explicitly. Presumably if it is incrementNumber you're going to use in data binding you'll need to bind the 'this' pointer in, if you do that using Function.bind the function you need to mark as supported for processing will be the result of Function.bind.

    Friday, August 24, 2012 5:42 AM
  • Thanks, joshwil.

    Yes I am using the incrementNumber function to bind to a button. This is line 3 in my original HTML listing:

    <button data-win-bind="click:incrementNumber">+</button>

    I guess I'm a little confused because the requireSupportedForProcessing function topic explicitly says:

    All functions that have been declared using WinJS.Class.define, WinJS.Class.derive, WinJS.UI.Pages.define, or WinJS.Binding.converter are automatically marked as supported for declarative processing.

    Is the documentation just wrong then?

    Friday, August 24, 2012 1:23 PM
  • The wording is a little confusing.  Not all functions in the NS define are set.  Only the constructor of your mixin.  I debugged this and you can see that indeed that it is not set.  Only the constructor is marked, not the individual functions.

    -Jeff


    Jeff Sanders (MSFT)

    Monday, August 27, 2012 7:21 PM
    Moderator
  • thanks, Jeff!
    Monday, August 27, 2012 8:54 PM