Created
October 11, 2016 18:59
-
-
Save demosifter/b25ca1e811c2552bf1cd88ffc659cbfe 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
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