Lately, I’ve been looking into patterns in Knockout that will allow separation between view- and backend-related code. I’ve been trying to find methods of transparently communicating to a server API when relevant view model properties change, without explicitly concerning the view code.
This post describes one of the solutions I’ve used for my current project, which I will name proxy objects, lacking a better name. We’ll look into how to set up observable objects that are automatically persisted by posting to an API, and thus decoupling it from the view model.
We’re going to build something like the example below, where the server is notified as the user changes data in the fields. In the right hand column we’ll log “server” (a.k.a console.log) calls to our API. Edit the fields to see what calls are made.
Your new post is loading...