Skip to content

Instantly share code, notes, and snippets.

//...
constructor() {
// You have to call the super() method to initialize the base class.
super();
this.controller.subscribe('counts', this.onCounts.bind(this));
}
// for more info: https://docs.redsift.com/docs/client-code-siftview
presentView(value) {
console.log('counter: presentView: ', value);
constructor() {
// You have to call the super() method to initialize the base class.
super();
this._suHandler = this.onStorageUpdate.bind(this);
}
loadView(state) {
console.log('counter: loadView', state);
this.storage.subscribe(['count'], this._suHandler);
module.exports = function (got) {
const json = got.in.data.map(d => JSON.parse(d.value));
const query = got.query;
const threadId = query[0];
let newestCount = json
.sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime())
.shift().count;
return [{
return {
key: `${value.threadId}/${value.id}`, // instead of 'value.id
value: {
count: count,
date: value.date
}
}
@demosifter
demosifter / how-to-dag-stores-1.json
Created October 11, 2016 16:24
implementing key hierarchy
"stores":{
"messageCounts" : {
"key$schema":"string/string"
}
}
@demosifter
demosifter / how-to-dag-outputs-2.json
Created October 11, 2016 16:12
exporting to _email.tid
"outputs":{
"exports":{
"count" : {
"key$schema":"string"
},
"threads": {
"import": "_email.tid"
}
}
}
module.exports = function (got) {
const total = got.in.data.reduce((p, d) => p + parseInt(d.value), 0);
return {
key: 'word_count',
value: total
}
}
@demosifter
demosifter / how-to-dag-3.json
Last active October 11, 2016 16:18
adding a second node and making first node emit to store
"nodes":[{
"#": "First Node",
"input": {
"bucket": "gmailEmails"
},
"implementation": {
"javascript": "server/node1.js"
},
"outputs": {
"messageCounts": {}
return {
key: value.id, // instead of 'word_count'
value: count
}
"dag": {
...
"nodes":[{
"#": "First Node",
"input": {
"bucket": "gmailEmails"
},
"implementation": {
"javascript": "server/node1.js"
},