Skip to content

Instantly share code, notes, and snippets.

@demosifter
Created October 11, 2016 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save demosifter/b25ca1e811c2552bf1cd88ffc659cbfe to your computer and use it in GitHub Desktop.
Save demosifter/b25ca1e811c2552bf1cd88ffc659cbfe to your computer and use it in GitHub Desktop.
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);
switch (state.type) {
case 'email-thread':
return {
html: 'email-thread.html',
data: {}
};
case 'summary':
return {
html: 'summary.html',
data: this.getCount()
};
default:
console.error('counter: unknown Sift type: ', state.type);
}
}
// Event: storage update
onStorageUpdate(value) {
console.log('counter: onStorageUpdate: ', value);
return this.getCount().then(xe => {
// Publish events from 'x' to view
this.publish('counts', xe);
});
}
getCount() {
return this.storage.get({
bucket: 'count',
keys: ['word_count']
}).then((values) => {
console.log('counter: getCount returned:', values);
return values[0];
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment