This is a migrated thread and some comments may be shown as answers.

Confused about when bindings are triggered.

4 Answers 129 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
Stacey
Top achievements
Rank 1
Stacey asked on 07 Dec 2013, 09:33 PM
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.

4 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 09 Dec 2013, 08:53 AM
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!
0
Stacey
Top achievements
Rank 1
answered on 09 Dec 2013, 06:55 PM
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.
0
Stacey
Top achievements
Rank 1
answered on 09 Dec 2013, 08:57 PM
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?
0
Atanas Korchev
Telerik team
answered on 10 Dec 2013, 08:01 AM
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!
Tags
MVVM
Asked by
Stacey
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Stacey
Top achievements
Rank 1
Share this question
or