[Pkg-javascript-commits] [backbone] 26/74: Fixing backbone-localstorage links.

Jonas Smedegaard js at moszumanska.debian.org
Sat May 3 16:59:06 UTC 2014


This is an automated email from the git hooks/post-receive script.

js pushed a commit to tag 0.3.0
in repository backbone.

commit de4b2b35d9a36a905293e0ce865091b0f3695afe
Author: Jeremy Ashkenas <jashkenas at gmail.com>
Date:   Tue Oct 26 11:50:39 2010 -0400

    Fixing backbone-localstorage links.
---
 Rakefile                                           |  2 +-
 docs/backbone-localstorage.html                    | 56 ++++++++++++++++++++++
 docs/todos.html                                    |  4 +-
 ...ne.localstorage.js => backbone-localstorage.js} |  0
 examples/todos/index.html                          |  2 +-
 examples/todos/todos.js                            |  2 +-
 index.html                                         |  2 +-
 7 files changed, 62 insertions(+), 6 deletions(-)

diff --git a/Rakefile b/Rakefile
index b71e488..bf2672d 100644
--- a/Rakefile
+++ b/Rakefile
@@ -11,7 +11,7 @@ desc "build the docco documentation"
 task :doc do
   system [
     'docco backbone.js',
-    'docco examples/todos/todos.js examples/backbone.localstorage.js'
+    'docco examples/todos/todos.js examples/backbone-localstorage.js'
   ].join(' && ')
 end
 
diff --git a/docs/backbone-localstorage.html b/docs/backbone-localstorage.html
new file mode 100644
index 0000000..ba1e9e9
--- /dev/null
+++ b/docs/backbone-localstorage.html
@@ -0,0 +1,56 @@
+<!DOCTYPE html>  <html> <head>   <title>backbone-localstorage.js</title>   <meta http-equiv="content-type" content="text/html; charset=UTF-8">   <link rel="stylesheet" media="all" href="docco.css" /> </head> <body>   <div id="container">     <div id="background"></div>            <div id="jump_to">         Jump To …         <div id="jump_wrapper">           <div id="jump_page">                                           <a class="source" href="backbone-localstorage.html">           [...]
+persistence. Models are given GUIDS, and saved into a JSON object. Simple
+as that.</p>             </td>             <td class="code">               <div class="highlight"><pre></pre></div>             </td>           </tr>                               <tr id="section-2">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-2">¶</a>               </div>               <p>Generate four random hex digits.</p>             </td>             <td class="code">               <div class="highlight"><p [...]
+   <span class="k">return</span> <span class="p">(((</span><span class="mi">1</span><span class="o">+</span><span class="nb">Math</span><span class="p">.</span><span class="nx">random</span><span class="p">())</span><span class="o">*</span><span class="mh">0x10000</span><span class="p">)</span><span class="o">|</span><span class="mi">0</span><span class="p">).</span><span class="nx">toString</span><span class="p">(</span><span class="mi">16</span><span class="p">).</span><span class="nx" [...]
+<span class="p">};</span></pre></div>             </td>           </tr>                               <tr id="section-3">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-3">¶</a>               </div>               <p>Generate a pseudo-GUID by concatenating random hexadecimal.</p>             </td>             <td class="code">               <div class="highlight"><pre><span class="kd">function</span> <span class="nx [...]
+   <span class="k">return</span> <span class="p">(</span><span class="nx">S4</span><span class="p">()</span><span class="o">+</span><span class="nx">S4</span><span class="p">()</span><span class="o">+</span><span class="s2">"-"</span><span class="o">+</span><span class="nx">S4</span><span class="p">()</span><span class="o">+</span><span class="s2">"-"</span><span class="o">+</span><span class="nx">S4</span><span class="p">()</span><span class="o">+</span><span class=" [...]
+<span class="p">};</span></pre></div>             </td>           </tr>                               <tr id="section-4">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-4">¶</a>               </div>               <p>Our Store is represented by a single JS object in <em>localStorage</em>. Create it
+with a meaningful name, like the name you'd give a table.</p>             </td>             <td class="code">               <div class="highlight"><pre><span class="kd">var</span> <span class="nx">Store</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">name</span><span class="p">)</span> <span class="p">{</span>
+  <span class="k">this</span><span class="p">.</span><span class="nx">name</span> <span class="o">=</span> <span class="nx">name</span><span class="p">;</span>
+  <span class="kd">var</span> <span class="nx">store</span> <span class="o">=</span> <span class="nx">localStorage</span><span class="p">.</span><span class="nx">getItem</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">name</span><span class="p">);</span>
+  <span class="k">this</span><span class="p">.</span><span class="nx">data</span> <span class="o">=</span> <span class="p">(</span><span class="nx">store</span> <span class="o">&&</span> <span class="nx">JSON</span><span class="p">.</span><span class="nx">parse</span><span class="p">(</span><span class="nx">store</span><span class="p">))</span> <span class="o">||</span> <span class="p">{};</span>
+<span class="p">};</span>
+
+<span class="nx">_</span><span class="p">.</span><span class="nx">extend</span><span class="p">(</span><span class="nx">Store</span><span class="p">.</span><span class="nx">prototype</span><span class="p">,</span> <span class="p">{</span></pre></div>             </td>           </tr>                               <tr id="section-5">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-5">¶</a>               </div>        [...]
+    <span class="nx">localStorage</span><span class="p">.</span><span class="nx">setItem</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">name</span><span class="p">,</span> <span class="nx">JSON</span><span class="p">.</span><span class="nx">stringify</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">data</span><span class="p">));</span>
+  <span class="p">},</span></pre></div>             </td>           </tr>                               <tr id="section-6">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-6">¶</a>               </div>               <p>Add a model, giving it a (hopefully)-unique GUID, if it doesn't already
+have an id of it's own.</p>             </td>             <td class="code">               <div class="highlight"><pre>  <span class="nx">create</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">model</span><span class="p">)</span> <span class="p">{</span>
+    <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">model</span><span class="p">.</span><span class="nx">id</span><span class="p">)</span> <span class="nx">model</span><span class="p">.</span><span class="nx">id</span> <span class="o">=</span> <span class="nx">model</span><span class="p">.</span><span class="nx">attributes</span><span class="p">.</span><span class="nx">id</span> <span class="o">=</span> <span class="nx">guid</span><span class="p [...]
+    <span class="k">this</span><span class="p">.</span><span class="nx">data</span><span class="p">[</span><span class="nx">model</span><span class="p">.</span><span class="nx">id</span><span class="p">]</span> <span class="o">=</span> <span class="nx">model</span><span class="p">;</span>
+    <span class="k">this</span><span class="p">.</span><span class="nx">save</span><span class="p">();</span>
+    <span class="k">return</span> <span class="nx">model</span><span class="p">;</span>
+  <span class="p">},</span></pre></div>             </td>           </tr>                               <tr id="section-7">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-7">¶</a>               </div>               <p>Update a model by replacing its copy in <code>this.data</code>.</p>             </td>             <td class="code">               <div class="highlight"><pre>  <span class="nx">update</span><span clas [...]
+    <span class="k">this</span><span class="p">.</span><span class="nx">data</span><span class="p">[</span><span class="nx">model</span><span class="p">.</span><span class="nx">id</span><span class="p">]</span> <span class="o">=</span> <span class="nx">model</span><span class="p">;</span>
+    <span class="k">this</span><span class="p">.</span><span class="nx">save</span><span class="p">();</span>
+    <span class="k">return</span> <span class="nx">model</span><span class="p">;</span>
+  <span class="p">},</span></pre></div>             </td>           </tr>                               <tr id="section-8">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-8">¶</a>               </div>               <p>Retrieve a model from <code>this.data</code> by id.</p>             </td>             <td class="code">               <div class="highlight"><pre>  <span class="nx">find</span><span class="o">:</span> [...]
+    <span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="nx">data</span><span class="p">[</span><span class="nx">model</span><span class="p">.</span><span class="nx">id</span><span class="p">];</span>
+  <span class="p">},</span></pre></div>             </td>           </tr>                               <tr id="section-9">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-9">¶</a>               </div>               <p>Return the array of all models currently in storage.</p>             </td>             <td class="code">               <div class="highlight"><pre>  <span class="nx">findAll</span><span class="o">:</s [...]
+    <span class="k">return</span> <span class="nx">_</span><span class="p">.</span><span class="nx">values</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">data</span><span class="p">);</span>
+  <span class="p">},</span></pre></div>             </td>           </tr>                               <tr id="section-10">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-10">¶</a>               </div>               <p>Delete a model from <code>this.data</code>, returning it.</p>             </td>             <td class="code">               <div class="highlight"><pre>  <span class="nx">destroy</span><span class=" [...]
+    <span class="k">delete</span> <span class="k">this</span><span class="p">.</span><span class="nx">data</span><span class="p">[</span><span class="nx">model</span><span class="p">.</span><span class="nx">id</span><span class="p">];</span>
+    <span class="k">this</span><span class="p">.</span><span class="nx">save</span><span class="p">();</span>
+    <span class="k">return</span> <span class="nx">model</span><span class="p">;</span>
+  <span class="p">}</span>
+
+<span class="p">});</span></pre></div>             </td>           </tr>                               <tr id="section-11">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-11">¶</a>               </div>               <p>Override <code>Backbone.sync</code> to use delegate to the model or collection's
+<em>localStorage</em> property, which should be an instance of <code>Store</code>.</p>             </td>             <td class="code">               <div class="highlight"><pre><span class="nx">Backbone</span><span class="p">.</span><span class="nx">sync</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">method</span><span class="p">,</span> <span class="nx">model</span><span class="p">,</span> <span class="nx">success</span><span cla [...]
+
+  <span class="kd">var</span> <span class="nx">resp</span><span class="p">;</span>
+  <span class="kd">var</span> <span class="nx">store</span> <span class="o">=</span> <span class="nx">model</span><span class="p">.</span><span class="nx">localStorage</span> <span class="o">||</span> <span class="nx">model</span><span class="p">.</span><span class="nx">collection</span><span class="p">.</span><span class="nx">localStorage</span><span class="p">;</span>
+
+  <span class="k">switch</span> <span class="p">(</span><span class="nx">method</span><span class="p">)</span> <span class="p">{</span>
+    <span class="k">case</span> <span class="s2">"read"</span><span class="o">:</span>    <span class="nx">resp</span> <span class="o">=</span> <span class="nx">model</span><span class="p">.</span><span class="nx">id</span> <span class="o">?</span> <span class="nx">store</span><span class="p">.</span><span class="nx">find</span><span class="p">(</span><span class="nx">model</span><span class="p">)</span> <span class="o">:</span> <span class="nx">store</span><span class="p">.</s [...]
+    <span class="k">case</span> <span class="s2">"create"</span><span class="o">:</span>  <span class="nx">resp</span> <span class="o">=</span> <span class="nx">store</span><span class="p">.</span><span class="nx">create</span><span class="p">(</span><span class="nx">model</span><span class="p">);</span>                            <span class="k">break</span><span class="p">;</span>
+    <span class="k">case</span> <span class="s2">"update"</span><span class="o">:</span>  <span class="nx">resp</span> <span class="o">=</span> <span class="nx">store</span><span class="p">.</span><span class="nx">update</span><span class="p">(</span><span class="nx">model</span><span class="p">);</span>                            <span class="k">break</span><span class="p">;</span>
+    <span class="k">case</span> <span class="s2">"delete"</span><span class="o">:</span>  <span class="nx">resp</span> <span class="o">=</span> <span class="nx">store</span><span class="p">.</span><span class="nx">destroy</span><span class="p">(</span><span class="nx">model</span><span class="p">);</span>                           <span class="k">break</span><span class="p">;</span>
+  <span class="p">}</span>
+
+  <span class="k">if</span> <span class="p">(</span><span class="nx">resp</span><span class="p">)</span> <span class="p">{</span>
+    <span class="nx">success</span><span class="p">(</span><span class="nx">resp</span><span class="p">);</span>
+  <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
+    <span class="nx">error</span><span class="p">(</span><span class="s2">"Record not found"</span><span class="p">);</span>
+  <span class="p">}</span>
+<span class="p">};</span>
+
+</pre></div>             </td>           </tr>                </tbody>     </table>   </div> </body> </html> 
\ No newline at end of file
diff --git a/docs/todos.html b/docs/todos.html
index eb31901..887ed73 100644
--- a/docs/todos.html
+++ b/docs/todos.html
@@ -1,6 +1,6 @@
-<!DOCTYPE html>  <html> <head>   <title>todos.js</title>   <meta http-equiv="content-type" content="text/html; charset=UTF-8">   <link rel="stylesheet" media="all" href="docco.css" /> </head> <body>   <div id="container">     <div id="background"></div>            <div id="jump_to">         Jump To …         <div id="jump_wrapper">           <div id="jump_page">                                           <a class="source" href="backbone.localstorage.html">                 backbone. [...]
+<!DOCTYPE html>  <html> <head>   <title>todos.js</title>   <meta http-equiv="content-type" content="text/html; charset=UTF-8">   <link rel="stylesheet" media="all" href="docco.css" /> </head> <body>   <div id="container">     <div id="background"></div>            <div id="jump_to">         Jump To …         <div id="jump_wrapper">           <div id="jump_page">                                           <a class="source" href="backbone-localstorage.html">                 backbone- [...]
 <a href="http://jgn.me/">Jérôme Gravel-Niquet</a>. This demo uses a simple
-<a href="backbone.localstorage.html">LocalStorage adapter</a>
+<a href="backbone-localstorage.html">LocalStorage adapter</a>
 to persist Backbone models within your browser.</p>             </td>             <td class="code">               <div class="highlight"><pre></pre></div>             </td>           </tr>                               <tr id="section-2">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-2">¶</a>               </div>               <p>Load the application once the DOM is ready, using <code>jQuery.ready</code>:</p>      [...]
       <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="k">this</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="s2">"content"</span><span class="p">))</span> <span class="p">{</span>
         <span class="k">this</span><span class="p">.</span><span class="nx">set</span><span class="p">({</span><span class="s2">"content"</span><span class="o">:</span> <span class="k">this</span><span class="p">.</span><span class="nx">EMPTY</span><span class="p">});</span>
diff --git a/examples/backbone.localstorage.js b/examples/backbone-localstorage.js
similarity index 100%
rename from examples/backbone.localstorage.js
rename to examples/backbone-localstorage.js
diff --git a/examples/todos/index.html b/examples/todos/index.html
index c78c63d..ff00038 100644
--- a/examples/todos/index.html
+++ b/examples/todos/index.html
@@ -8,7 +8,7 @@
     <script src="../../test/vendor/jquery-1.4.2.js"></script>
     <script src="../../test/vendor/underscore-1.1.0.js"></script>
     <script src="../../backbone.js"></script>
-    <script src="../backbone.localstorage.js"></script>
+    <script src="../backbone-localstorage.js"></script>
     <script src="todos.js"></script>
   </head>
 
diff --git a/examples/todos/todos.js b/examples/todos/todos.js
index 90d231f..530c227 100644
--- a/examples/todos/todos.js
+++ b/examples/todos/todos.js
@@ -1,6 +1,6 @@
 // An example Backbone application contributed by
 // [Jérôme Gravel-Niquet](http://jgn.me/). This demo uses a simple
-// [LocalStorage adapter](backbone.localstorage.html)
+// [LocalStorage adapter](backbone-localstorage.html)
 // to persist Backbone models within your browser.
 
 // Load the application once the DOM is ready, using `jQuery.ready`:
diff --git a/index.html b/index.html
index b00ad51..3bfab0a 100644
--- a/index.html
+++ b/index.html
@@ -1519,7 +1519,7 @@ var DocumentView = Backbone.View.extend({
       that is bundled in the repository as Backbone example. If you're wondering
       where to get started with Backbone in general, take a moment to
       <a href="docs/todos.html">read through the annotated source</a>. The app uses a
-      <a href="docs/backbone.localstorage.html">LocalStorage adapter</a>
+      <a href="docs/backbone-localstorage.html">LocalStorage adapter</a>
       to transparently save all of your todos within your browser, instead of
       sending them to a server. Jérôme also has a version hosted at
       <a href="http://localtodos.com/">localtodos.com</a> that uses a

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/backbone.git



More information about the Pkg-javascript-commits mailing list