Skip to content

Instantly share code, notes, and snippets.

@segphault segphault/app.js
Created Jun 15, 2015

Embed
What would you like to do?
Todo list app built with deepstream and RethinkDB
var DSServer = require("deepstream.io");
var DSRethinkConnector = require("deepstream.io-storage-rethinkdb");
var server = new DSServer();
server.set("host", "localhost");
server.set("port", 6020);
server.set("storage", new DSRethinkConnector({
port: 28015,
host: "localhost",
splitChar: "/",
defaultTable: "dsdemo"
}));
server.start();
<html>
<head>
<script src="bower_components/deepstream.io-client-js/dist/deepstream.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/vue/0.12.1/vue.min.js"></script>
</head>
<body>
<div id="todolist">
<ul>
<li v-repeat="items" v-on="click: toggle">
<label>
<input type="checkbox" checked="{{done}}">
{{text}}
</label>
</li>
</ul>
<input type="text" v-model="newItemName" placeholder="New Item">
<button v-on="click: newItem">Add</button>
</div>
<script>
var ds = deepstream("localhost:6020").login();
var list = ds.record.getList("todos");
function wrapRecord(record) {
record.subscribe(function(data) {
for (var prop in data)
if (data.hasOwnProperty(prop))
record.$set(prop, data[prop]);
});
return record;
}
var todo = new Vue({
el: "#todolist",
data: {
items: []
},
methods: {
toggle: function(ev) {
if (ev.target.checked != undefined)
todo.items[ev.targetVM.$index].set("done", ev.target.checked);
},
newItem: function() {
var name = "todos/" + ds.getUid();
var record = ds.record.getRecord(name);
record.set({text: this.newItemName, done: false});
list.addEntry(name);
},
},
ready: function() {
list.subscribe(function(data) {
data.forEach(function(name) {
var record = ds.record.getRecord(name);
record.whenReady(function() {
todo.items.push(wrapRecord(record));
});
});
});
}
});
</script>
</body>
</html>
@alejandropaciotti

This comment has been minimized.

Copy link

alejandropaciotti commented Jan 12, 2016

Hi: toogle function should be:

function(ev) {
          if (ev.target.checked != undefined)
            {todo.items[ev.targetVM.$index].set("done", ev.target.checked)}
          else {
            todo.items[ev.targetVM.$index].set("done", !ev.target.checked)
          }
        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.