Created
February 28, 2015 02:33
-
-
Save enjalot/d4f604f24b893ec90724 to your computer and use it in GitHub Desktop.
This file contains 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
.idea | |
node_modules | |
.DS_Store |
This file contains 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
<Body:> | |
<h1>Hello, world!</h1> | |
hey there!<br> | |
notebook id: {{_page.notebookId}}<br> | |
cells:<br> | |
<ul> | |
{{each _page.cells as #cell,#i}} | |
<li> | |
cell {{#i}} {{#cell.id}} | |
</li> | |
{{/each}} | |
</ul> | |
<a on-click="addCell()">Add Cell</a> |
This file contains 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 derby = require('derby'); | |
var app = module.exports = derby.createApp('notebook', __filename); | |
app.use(require('derby-debug')); | |
app.loadViews(__dirname); | |
app.get('/', function(page, model) { | |
notebookQuery = model.query("notebooks", {name: "foo"}) | |
notebookQuery.fetch(function(err) { | |
notebooks = notebookQuery.get() | |
var notebookId; | |
if(!notebooks.length) { | |
notebookId = model.add("notebooks", {name: "foo"}) | |
} else { | |
notebookId = notebooks[0].id | |
console.log("already there", notebookId) | |
} | |
var notebook = model.at("notebooks" + notebookId) | |
var cells = model.query("cells", {_notebook: notebookId}) | |
model.subscribe(notebook, cells, function(err) { | |
model.set("_page.notebookId", notebookId) | |
var filter = model.filter("cells", // model.scope gives you access to the root scope | |
function(c){ return c._notebook === notebookId }) | |
.sort(function(a,b) { if(b._prev === a.id) return -1; return 1;}) | |
model.ref("_page.cells", filter); // reference the filtered cells in our local scope | |
model.ref("_page.notebook", notebook) | |
page.render(); | |
}) | |
}) | |
}); | |
// global view function | |
app.proto.addCell = function() { | |
var model = this.model; | |
var notebookId = model.get("_page.notebookId") | |
var newCell = { _notebook: notebookId } | |
var cellId = model.add("cells", newCell) | |
} |
This file contains 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
{ | |
"name": "notebook", | |
"version": "1.0.0", | |
"description": "Mini derby-app", | |
"main": "index.js", | |
"scripts": { | |
"start": "node server.js" | |
}, | |
"keywords": [ | |
"derby", "mini" | |
], | |
"dependencies": { | |
"derby-starter": "^0.2.6", | |
"derby-debug": "^0.1.0" | |
}, | |
"author": "", | |
"license": "MIT" | |
} |
This file contains 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
require('derby-starter').run(__dirname, {port: 3000}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment