Single Page Apps – Writing a LoDash/Underscore Plugin for SammyJS
Although SammyJS is a router that provides you with file loading of data and templates. You load templates and data using Sammy’s plugins.
In this tutorial, you will learn how you can use sammy.load to load JSON data, and then use LoDash (or Underscore) to _.find()
to retrieve the item based on the value provided in the sammy route. And you will combine the template and data using a custom Sammy plugin.
Why LoDash?
LoDash or Underscore provide great methods for working with collections and arrays. There are subtle differences in these two libraries. But for this tutorial, they provide the same functionality.
Use these libraries to “slice and dice” your data. In the case of this tutorial, you will use _.find()
. In your real life applications, there will be more complex ways of manipulating your data, that LoDash can provide.
LoDash includes _.template()
. The template method compiles a set of HTML code and turns it into JavaScript. The templates can include _ and complex JavaScript functions.
Continue reading “Single Page Apps – Writing a LoDash/Underscore Plugin for SammyJS”