KnockoutJS supports the idea of an observable object. This is similar to WPF/XAML concept of INotifyPropertyChanged interface. Most KnockoutJS dev's I've talked with use KnockoutJS's observable everywhere. But there are cases when you don't need it.
The biggest problem I see is that some people think that to get two-way binding you need observable. For example, here is a JSFiddle with a typical (but simple) KnockoutJS example:
Here you see that the view model (e.g. src) is using an observable to create the properties. In the HTML, we have the name field bound twice...to the input box and to a div. This means than when we change the text in the first input box and that box loses focus, then the div changes as well. This is at the heart of what KnockoutJS's observable does. But in some cases, if you don't need the notification part of the functionality, a simple property is more efficient:
In this case, the code is identical but the viewmodel (e.g. src) is just using plain old JS members. While changing the text in the name input field doesn't make the div change (because the notification is missing), it does in fact handle two way binding. You can see this if you click the button (which pops up an alert showing the name in the view model.
For large apps that have a lot of bindings, this efficiency is helpful. Knowing when you can avoid using observable can help improve overall KnockoutJS performance.
What do you think?
|Using Visual Studio Code for ASP.NET Core Projects (new)|
|Implementing and Securing an API with ASP.NET Core (new)|
|Building a Web App with ASP.NET Core, MVC6, EF Core and AngularJS|
|Building a Web App with ASP.NET5, MVC6, EF7, and AngularJS (Retired)|
|Best Practices in ASP.NET: Entities, Validation, and View Models|
|Front-End Web Development Quick Start|
|Lessons from Real World .NET Code Reviews|
|Node.js for .NET Developers|
|Application Name||WilderBlog||Environment Name||Production|
|Application Ver||188.8.131.52||Runtime Framework||.NETCoreApp,Version=v2.0|
|App Path||D:\home\site\wwwroot\||Runtime Version||.NET Core 4.6.00001.0|
|Operating System||Microsoft Windows 6.2.9200||Runtime Arch||X86|