PageRenderTime 26ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/README.md

https://github.com/cworsley4/Backbone.localStorage
Markdown | 120 lines | 85 code | 35 blank | 0 comment | 0 complexity | 6d6afc1cd63bb5a090a0be04b447e27d MD5 | raw file
  1. # Backbone localStorage Adapter v1.1.5
  2. [![Build Status](https://secure.travis-ci.org/jeromegn/Backbone.localStorage.png?branch=master)](http://travis-ci.org/jeromegn/Backbone.localStorage)
  3. Quite simply a localStorage adapter for Backbone. It's a drop-in replacement for Backbone.Sync() to handle saving to a localStorage database.
  4. [![Gittip](http://badgr.co/gittip/jeromegn.png)](https://www.gittip.com/jeromegn/)
  5. ## Usage
  6. Include Backbone.localStorage after having included Backbone.js:
  7. ```html
  8. <script type="text/javascript" src="backbone.js"></script>
  9. <script type="text/javascript" src="backbone.localStorage.js"></script>
  10. ```
  11. Create your collections like so:
  12. ```javascript
  13. window.SomeCollection = Backbone.Collection.extend({
  14. localStorage: new Backbone.LocalStorage("SomeCollection"), // Unique name within your app.
  15. // ... everything else is normal.
  16. });
  17. ```
  18. ### RequireJS
  19. Include [RequireJS](http://requirejs.org):
  20. ```html
  21. <script type="text/javascript" src="lib/require.js"></script>
  22. ```
  23. RequireJS config:
  24. ```javascript
  25. require.config({
  26. paths: {
  27. jquery: "lib/jquery",
  28. underscore: "lib/underscore",
  29. backbone: "lib/backbone",
  30. localstorage: "lib/backbone.localStorage"
  31. }
  32. });
  33. ```
  34. Define your collection as a module:
  35. ```javascript
  36. define("someCollection", ["localstorage"], function() {
  37. var SomeCollection = Backbone.Collection.extend({
  38. localStorage: new Backbone.LocalStorage("SomeCollection") // Unique name within your app.
  39. });
  40. return new SomeCollection();
  41. });
  42. ```
  43. Require your collection:
  44. ```javascript
  45. require(["someCollection"], function(someCollection) {
  46. // ready to use someCollection
  47. });
  48. ```
  49. ### CommonJS
  50. If you're using [browserify](https://github.com/substack/node-browserify).
  51. ```javascript
  52. var Backbone.LocalStorage = require("backbone.localstorage");
  53. ```
  54. ##Support
  55. If you're having a problem with using the project, get help at CodersClan.
  56. <a href="http://codersclan.net/forum/index.php?repo_id=67"><img src="http://www.codersclan.net/graphics/getSupport_blue_big.png" width="160"></a>
  57. ## Contributing
  58. You'll need node and to `npm install` before being able to run the minification script.
  59. 1. Fork;
  60. 2. Write code, with tests;
  61. 3. `make test` or `open spec/runner.html`;
  62. 4. Create a pull request.
  63. Have fun!
  64. ## Acknowledgments
  65. - [Mark Woodall](https://github.com/llad): initial tests (now refactored);
  66. - [Martin H채cker](https://github.com/dwt): many fixes and the test isolation.
  67. ## License
  68. Licensed under MIT license
  69. Copyright (c) 2010 Jerome Gravel-Niquet
  70. Permission is hereby granted, free of charge, to any person obtaining
  71. a copy of this software and associated documentation files (the
  72. "Software"), to deal in the Software without restriction, including
  73. without limitation the rights to use, copy, modify, merge, publish,
  74. distribute, sublicense, and/or sell copies of the Software, and to
  75. permit persons to whom the Software is furnished to do so, subject to
  76. the following conditions:
  77. The above copyright notice and this permission notice shall be
  78. included in all copies or substantial portions of the Software.
  79. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  80. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  81. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  82. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  83. LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  84. OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  85. WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.