locked
More chaining support in WinRT

    General discussion

  • I like how the whole async, promise things are working in WinJS.

    I stumbled over this piece of code though:

     

    //Create the message dialog and set its content and title
            var msg = new Windows.UI.Popups.MessageDialog("You have exceeded your trial period.", "Would you like to continue your trial or upgrade to a full membership?");
            
            //Add buttons and set their callback functions
            msg.commands.append(new Windows.UI.Popups.UICommand("Continue trial", function (command) {
                sdkSample.displayStatus("The Continue trial button has been selected.");
                }));
            msg.commands.append(new Windows.UI.Popups.UICommand("Upgrade", function (command) {
                sdkSample.displayStatus("The Upgrade button has been selected.");    
            }));
    
            //Show the message dialog
            msg.showAsync().operation.start();  
    

     


    And I'd like it to benefit from chaining as well.

    How about that?

     

    new Windows.UI.Popups.MessageDialog("You have exceeded your trial period.", "Would you like to continue your trial or upgrade to a full membership?")
      .commands.append(new Windows.UI.Popups.UICommand("Continue trial", function (command) {
        sdkSample.displayStatus("The Continue trial button has been selected.");
      }))
      .commands.append(new Windows.UI.Popups.UICommand("Upgrade", function (command) {
        sdkSample.displayStatus("The Upgrade button has been selected.");    
      })).showAsync().operation.start();
    

    An no more msg var even :)

    What you think?

     

    Thursday, November 17, 2011 4:46 PM

All replies

  • This will not work!

    .commands.append() does not return a MessageDialog.


    Jeff Sanders (MSFT)
    Thursday, November 17, 2011 8:34 PM
    Moderator
  • I know that it does not work at the moment. append() "returns" void at the moment. That's why I wrote it would be nice if it would support chaining.

    I guess the WinRT API is still not feature frozen so changing void return type to MessageDialog would not break current apps.

    So I had hoped the WinRT API guys would consider changing the returned type :)

    Friday, November 18, 2011 4:33 AM