Created
November 8, 2011 14:37
-
-
Save biilmann/1347891 to your computer and use it in GitHub Desktop.
Webpop storage module
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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