chore: add listener for favorite changes

This commit is contained in:
2018-09-06 18:15:35 -07:00
parent a15deb9602
commit c652eee096

View File

@@ -194,6 +194,19 @@
set: (id, val) => localStorage.setItem(id, JSON.stringify(val)), set: (id, val) => localStorage.setItem(id, JSON.stringify(val)),
}; };
// listeners
emitter.on('favorite', ({ id, isFav }) => {
const favs = store.get('favorites') || [];
const idx = favs.indexOf(id);
// remove previously favorited strain
if (idx >= 0 && !isFav) {
store.set('favorites', favs.filter(f => f !== id));
} else if (idx === -1 && isFav) {
store.set('favorites', favs.concat(id));
}
});
// vue helpers // vue helpers
Vue.filter('capitalize', value => { Vue.filter('capitalize', value => {
if (!value) return ''; if (!value) return '';