Skip to content

Instantly share code, notes, and snippets.

@aghull
Last active August 29, 2015 14:21
Show Gist options
  • Save aghull/e90c6abfc6213beb2a6e to your computer and use it in GitHub Desktop.
Save aghull/e90c6abfc6213beb2a6e to your computer and use it in GitHub Desktop.
// list_app.js
Slick = require('slick');
listItem = require('./data/list_item');
list = require('./data/list');
var MyListApp = module.exports = new Slick.App({
// init is called by the node after node starts up and hits addApplication which propagates the Node reference on this.node
init: function() {
// we register our data type containing field info and any custom logic
this.addModel('listItem', listItem);
// we create a chain to hold a list of our items
this.addChain('list', list);
...
this.chains.list.getUnread(function(unreadItems) {
// do stuff;
})
},
});
// data/list_item.js
var ListItem = module.exports = new Slick.Model({
fields: {
value: { type: 'string', short: 'v' },
state: { type: 'integer', short: 's' },
from: { type: 'string', short: 'f' }
},
// any default values can be set here
getInitialState: function() {
return {
state: 'unread'
};
},
// custom logic
markAsRead: function() {
this.set({ state: 'read' });
}
});
// data/list.js
var List = module.exports = new Slick.Chain({
model: listItem,
indexes: {
{ value: 'state', options: ['allowMulti'] },
{ value: 'from' }
},
getUnread: function(done) {
// find is just finder.equals + range.all
this.find('state', 'unread', done);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment