In this code snippet, you will learn how you can load the dependencies, initialize a module with values that you pass in, and then make public some of the methods.
And you will see how to put files in folders to help keep identify which modules you write in your app and which modules are from third parties.
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.
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.
Continue reading “Single Page Apps – Writing a LoDash/Underscore Plugin for SammyJS”
As you learned in the previous post, you learned how you can load templates inline in your app using RequireJS. The next step is to load and compile a template file. And for your offline app, learn how you can cache templates. Caching saves a round trip to the server, making your application incredibly responsive.
In this tutorial we will compile, load, and cache LoDash (or Underscore) templates and then use those templates to transform data in our single page app.
The technique uses RequireJS, so there is no more dynamic loading. Templates are bundled within your code which saves some HTTP requests.
Continue reading “Single Page App – Loading, Caching LoDash or Underscore Templates Using RequireJS, AppCache”
In the previous post, you learned how you can use RequireJS in projects to define your own loading order, and how to build your own modules.
This tutorial go into depth on how to use RequireJS for AMD (Asynchronous Module Definition) modules. You will write we can write our own modules and load them with RequireJS.
In this tutorial you will build a small app that uses LoDash and jQuery. If you want to use Underscore, just substitute Underscore for the LoDash references.
Although you can use a bunch of <script> tags to load the libraries, your page is blocked during the load. And you could minify them and maintain the order in your own code. But with RequireJS, you include the RequireJS source and let it load the files.
Continue reading “Single Page App – Using RequireJS Asynchronous Module Definition (AMD) Modules with jQuery, LoDash”
Comparison to Mustache, Handlebars
Mustache and Handlebars are what are known as “logic-less template engines.” With those libraries you cannot include any overly complex logic in the template. You get the most basic control structures needed to output data, keeping the HTML (or other content) clean.
Continue reading “Single Page App – HTML Templates With Logic Using Underscore, LoDash”