AmplifyJS is a set of components designed to solve common web application problems with a simplistic API. Amplify’s goal is to simplify all forms of data handling by providing a unified API for various data sources.
Your application may need more sophisticated control than is offered in Knockout, which provides for automatic updates in your view model. Knockout provides the observable pattern. But in the pattern described here Amplify’s publish/subscribe you do the publishing and the subscription.
In this post, you’ll learn the basics of how you can implement publish/subscribe pattern on the client using Amplify.
Continue reading “Single Page App – Separate UI from Model Using Publish, Subscribe Pattern using AmplifyJS”
Amplify store and Knockout can be great partners. For example, you can use client storage to improve user experience, remembering user preferences or previously entered values such that the user doesn’t have to start all over.
There is a tutorial on Knockout that provides for client storage. In the tutorial, Knockout uses Amplify to restore user data when the user revisits the site.
You can augment Knockout observables with additional functionality, by using extenders.
You can use extender to automatically store and restore any observable property. Continue reading “Single Page Apps – Store Your Data Locally in Knockout Using AmplifyJS”
In the previous post, Using Infuser to Asynchronously Load Your Templates, we took a detour into Infuser and how it can be used to call template code. But what about calling Knockout templates?
You will probably want to put a template into a separate file so you can reuse it across various pages on your site.
And you’ll see how you can use Infuser to configure your Knockout Template Engine.
You can use template feature in Knockoutjs to render your data. Templates are a straight forward way to build complex UI structure, often with repeating or nested blocks. You can use templates to show repeating data, such as data in tables or portfolios.
Templates as they are used in this post, are reusable chunks of HTML that relate to your observables in Knockout.
There are two main ways of using templates:
- Native templating where you use foreach, if, with and other control bindings. The control flow bindings use the HTML markup in your element and render against your data. The feature is built into Knockout.
- String-based templating connects Knockout to third-party template engine, such as jQuery Templates, MustacheJS, or underscore.
In our previous post Dynamic UI Using Observables with MVVM Using Knockout.js, you learned how you get started with Knockout.js and how you can detect and respond to changes on one object using observables.
Now if you want to detect and respond to changes of a collection of things, you can use an
observableArray. An observableArray tracks which objects are in the array, not the state of those objects.
observableArray tracks which objects it holds, and notifies listeners when objects are added or removed.
You can make the items themselves observable if you wish, but we’ll start with a basic observableArray.