Skip to content

Instantly share code, notes, and snippets.

@biilmann
Created November 8, 2011 14:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save biilmann/1347891 to your computer and use it in GitHub Desktop.
Save biilmann/1347891 to your computer and use it in GitHub Desktop.
Webpop storage module
The Basic Key/Value Store
-------------------------
Extensions now have access to a simple key/value store. To use it require the "storage" module:
var storage = require("storage");
// put an object in the store
storage.put("my-key", {title: "An object", text: "You can store any normal js object in the store});
// get an object from the store
var obj = storage.get("my-key");
Below is an example of a simple todo list implemented with the storage module.
<!doctype html>
<head>
<title>Personal Todo List</title>
</head>
<pop:user>
<h1>Todo List for <pop:name/></h1>
<pop:t:todos wrap="ol" break="li">
<pop:text/>
</pop:t:todos>
<form method="post">
<p>
<label>
Todo: <input required name="todo"/>
</label>
</p>
<p>
<button>Add todo item</button>
</p>
</form>
</pop:user>
<pop:no_user>
<h1>You need to be logged in to access the todo list</h1>
</pop:no_user>
var storage = require("storage");
exports.todos = function() {
var todos = storage.get("todos") || [];
if (request.method == "POST" && request.params.todo) {
todos.push({text: request.params.todo});
storage.put("todos", todos);
}
return todos;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment