aboutsummaryrefslogtreecommitdiffstats
path: root/src/stores/RecipePreviewsStore.js
diff options
context:
space:
mode:
authorLibravatar Stefan Malzner <stefan@adlk.io>2017-10-13 12:29:40 +0200
committerLibravatar Stefan Malzner <stefan@adlk.io>2017-10-13 12:29:40 +0200
commit58cda9cc7fb79ca9df6746de7f9662bc08dc156a (patch)
tree1211600c2a5d3b5f81c435c6896618111a611720 /src/stores/RecipePreviewsStore.js
downloadferdium-app-58cda9cc7fb79ca9df6746de7f9662bc08dc156a.tar.gz
ferdium-app-58cda9cc7fb79ca9df6746de7f9662bc08dc156a.tar.zst
ferdium-app-58cda9cc7fb79ca9df6746de7f9662bc08dc156a.zip
initial commit
Diffstat (limited to 'src/stores/RecipePreviewsStore.js')
-rw-r--r--src/stores/RecipePreviewsStore.js50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/stores/RecipePreviewsStore.js b/src/stores/RecipePreviewsStore.js
new file mode 100644
index 000000000..e25936f15
--- /dev/null
+++ b/src/stores/RecipePreviewsStore.js
@@ -0,0 +1,50 @@
1import { action, computed, observable } from 'mobx';
2import { debounce } from 'lodash';
3
4import Store from './lib/Store';
5import CachedRequest from './lib/CachedRequest';
6import Request from './lib/Request';
7import { gaEvent } from '../lib/analytics';
8
9export default class RecipePreviewsStore extends Store {
10 @observable allRecipePreviewsRequest = new CachedRequest(this.api.recipePreviews, 'all');
11 @observable featuredRecipePreviewsRequest = new CachedRequest(this.api.recipePreviews, 'featured');
12 @observable searchRecipePreviewsRequest = new Request(this.api.recipePreviews, 'search');
13
14 constructor(...args) {
15 super(...args);
16
17 // Register action handlers
18 this.actions.recipePreview.search.listen(this._search.bind(this));
19 }
20
21 @computed get all() {
22 return this.allRecipePreviewsRequest.execute().result || [];
23 }
24
25 @computed get featured() {
26 return this.featuredRecipePreviewsRequest.execute().result || [];
27 }
28
29 @computed get searchResults() {
30 return this.searchRecipePreviewsRequest.result || [];
31 }
32
33 @computed get dev() {
34 return this.stores.recipes.all.filter(r => r.local);
35 }
36
37 // Actions
38 @action _search({ needle }) {
39 if (needle !== '') {
40 this.searchRecipePreviewsRequest.execute(needle);
41
42 this._analyticsSearch(needle);
43 }
44 }
45
46 // Helper
47 _analyticsSearch = debounce((needle) => {
48 gaEvent('Recipe', 'search', needle);
49 }, 3000);
50}