Confused about when bindings are triggered.

5 posts, 0 answers
  1. Stacey
    Stacey avatar
    55 posts
    Member since:
    Aug 2013

    Posted 07 Dec 2013 Link to this post

    Given a view model, I have tried the following;

    var viewModel = new kendo.observable({
       Items: [],
      onUpdateItems: function(e){
         console.log('updating items');
     }
    });
    viewModel.Items.bind('change', function(e){
      viewModel.onUpdateItems(e);
    });
     
    viewModel.trigger("change", { field: "Items" });
    This does not cause the function to trigger. Though if I actually change items in the view, like interacting with it, it causes the function to fire. This doesn't make a lot of sense to me.
  2. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 09 Dec 2013 Link to this post

    Hi Stacey,

    If you listen to the change event of the viewModel (instead of viewModel.Items) things will work out as expected:
    var viewModel = new kendo.observable({
       Items: [],
      onUpdateItems: function(e){
         console.log('updating items');
     }
    });
    viewModel.bind('change', function(e){
      viewModel.onUpdateItems(e);
    });
      
    viewModel.trigger("change", { field: "Items" });


    Regards,
    Atanas Korchev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Kendo UI is VS 2017 Ready
  4. Stacey
    Stacey avatar
    55 posts
    Member since:
    Aug 2013

    Posted 09 Dec 2013 Link to this post

    That's a bit of a grievous error with the entire structure. You're basically saying we cannot depend on the bindings. That is extremely obtuse and wasteful to the entire process of building good view models.

    I get that a lot of conventions from other MVVM systems were "not used" in attempts to make kendo the "fastest", but more and more I keep seeing it is in fact very slow, and the way it binds to things is extremely unreliable. I find myself having to very, very constantly make manual calls to functions and templates that should have been updated just by using the "set" method, or by the value changing in a template, etc.

    Is there any chance that Kendo will keep improving on the MVVM system? Because right now, it is starting to get in the way, a lot.
  5. Stacey
    Stacey avatar
    55 posts
    Member since:
    Aug 2013

    Posted 09 Dec 2013 Link to this post

    I feel the tone of that post was a bit out of context, I apologize. Please allow me to be a bit more specific, and professional.

    I feel that a lot of these design decisions sacrifice more than they gain, as an end user. It confuses me when I read the documentation, and it tells me I can bind to properties of my view model, but the official support's answer to a problem with that is to just bind to the top level view model completely.

    It puzzles me when templates refuse to update without being explicitly called. This seems contrary to their intended purpose.

    Is there any chance that the MVVM system is going to be evolved further? Or is it being considered "Feature Locked" and only taking in bug fixes, for all intents and purposes?
  6. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 10 Dec 2013 Link to this post

    Hello Stacey, 

    You can observer any part of the view model. However when you trigger the change event of the top level you should not expect the change event of the inner level to be raised. Events only bubble up the hierarchy, not down.

    If you want to observe viewModel.Items then you should trigger the event from viewModel.Items:

    var viewModel = new kendo.observable({
       Items: [],
      onUpdateItems: function(e){
         alert('updating items');
     }
    });
    viewModel.Items.bind('change', function(e){
      viewModel.onUpdateItems(e);
    });
     
    viewModel.Items.trigger("change");

    Generally you shouldn't have to trigger the change event in order to manually update the UI. Kendo MVVM should handle this automatically. Could you please share with me a particular case where this doesn't happen? I will gladly assist you.

    Regards,
    Atanas Korchev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top
Kendo UI is VS 2017 Ready