Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
componentDidMount() {
const db = addons.getDatabase();
this.store = new DataStore(db);
this.stopListeningToComments = this.store.onComments(comments => {
this.setState({ comments });
});
// Clear the current notes on every story change.
this.stopListeningOnStory = this.props.api.onStory((kind, story) => {
// set the current selection
this.store.setCurrentStory(kind, story);
});
this.stopListingStoreLoading = this.store.onLoading(loading => {
this.setState({ loading });
});
this.init();
init() {
const db = addons.getDatabase();
if (typeof db.persister.getUser !== 'function') {
throw new Error('unable to get user info');
}
this.setState({ loading: true });
db.persister
.getUser()
.then(u => Promise.resolve(u), () => Promise.resolve(null))
.then(user => {
if (user) {
this.store.setCurrentUser(user);
this.setState({ user });
} else {
this.setState({ user: null });
}