background preloader

Backbone.js

Facebook Twitter

Backbone-localstorage.js. /** * Backbone localStorage Adapter * */ (function() { A simple module to replace Backbone.sync with localStorage-based persistence. Models are given GUIDS, and saved into a JSON object. Simple as that. Hold reference to Underscore.js and Backbone.js in the closure in order to make things work even if they are removed from the global namespace var _ = this. Generate four random hex digits. function S4() { return (((1+Math.random())*0x10000)|0).toString(16).substring(1);}; Generate a pseudo-GUID by concatenating random hexadecimal. function guid() { return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());}; Our Store is represented by a single JS object in localStorage. Backbone.LocalStorage = window.Store = function(name) { this.name = name; var store = this.localStorage().getItem(this.name); this.records = (store && store.split(",")) || [];}; _.extend(Backbone.LocalStorage.prototype, { create: function(model) { if (!

H. Backbone.localStorage. Quite simply a localStorage adapter for Backbone. It's a drop-in replacement for Backbone.Sync() to handle saving to a localStorage database. Usage Include Backbone.localStorage after having included Backbone.js: Create your collections like so: RequireJS Include RequireJS: RequireJS config: Define your collection as a module: Require your collection: require(["SomeCollection"], function(SomeCollection) { }); CommonJS If you're using browserify.

Install using npm install backbone.localstorage, and require the module. Backbone.LocalStorage = require("backbone.localstorage"); Support If you're having a problem with using the project, get help at CodersClan. Contributing You'll need node and to npm install before being able to run the minification script. Fork;Write code, with tests;make test or open spec/runner.html;Create a pull request.

Have fun! Acknowledgments Mark Woodall: initial tests (now refactored);Martin Häcker: many fixes and the test isolation. License Licensed under MIT license.

Development

Backbone.js. Backbone.js is a JavaScript library with a RESTful JSON interface and is based on the model–view–presenter (MVP) application design paradigm. Backbone is known for being lightweight, as its only dependency is on one JavaScript library,[2] Underscore.js. It is designed for developing single-page web applications,[3] and for keeping various parts of web applications (e.g. multiple clients and the server) synchronized.[4] Backbone was created by Jeremy Ashkenas, who is also known for CoffeeScript.[5] Use[edit] The following web applications are built with Backbone.js: References[edit] Further reading[edit] External links[edit] Official website.

Docs & tutorials. PaulUithol/Backbone-relational. References, Routing, And The Event Aggregator: Coordinating Views In Backbone.js. I recently found myself needing to facilitate communication between two backbone views. The first view is a medication – one that is currently being taken by a particular patient. The second view is the add/edit view that allows the patient to either add new medications or edit existing ones. When the edit icon is clicked for an existing medication, the edit form should be populated and the user should be able to edit the medication. Here’s what the screen looks like after I click on the edit icon (the pencil): There are a number of ways to make this work – the most basic of which is to have the views reference each other so that they can either call methods on each other or raise events. References I’ve done this a number of times and it works well. In this simple example, I have an event setup that listens to the edit icon click.

In some cases, though, this isn’t really an option – or, it may be an option that would cause a little extra code and work to make sure it works correctly. Thomas Davis. Back to home Backbone.js Tutorial – by noob for noobs The official website describes Backbone.js as a library to supply structure to Javascript heavy web applications. After using Backbone.js for a week I could never see myself building any sort of Javascript functionality regardless of size without using Backbone.js or alternatives. I have decided to write a quick introduction for those trying to grasp the mechanics behind it. I am only a beginner also and would love suggestions and tips to improve my code. I am also very curious to hear what you think about how MVC ties into Javascript development and the most effective library you have used for logically organizing your Javascript.

Would be great to get a discussion on MVC vs MVVM vs others etc leave comments at the bottom! Also could you implement this example better in another framework? Understanding the Model View Controller Paradigm I have used many frameworks which promote that they use MVC. Getting started <! Setting up the main view. Backbone.js. Backbone.js. Backbone.js and socket.io.