Skip to content

Commit 76fea86

Browse files
committed
fix(Todos): Add check if recipes have been loaded before downloading todos-recipe
1 parent e3c5157 commit 76fea86

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

src/features/todos/index.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,20 @@ export default function initTodos(stores, actions) {
2323
stores.todos = todosStore;
2424
const { features } = stores;
2525

26-
// Franz todos is now deeply baked into Franz, therefore the recipe is always needed
27-
if (!stores.recipes.isInstalled(TODOS_RECIPE_ID)) {
28-
console.log('Todos recipe is not installed, installing now...');
29-
actions.recipe.install({ recipeId: TODOS_RECIPE_ID });
30-
}
26+
reaction(
27+
() => stores.recipes.hasFinishedLoading,
28+
(hasFinishedLoading) => {
29+
if (hasFinishedLoading) {
30+
if (!stores.recipes.isInstalled(TODOS_RECIPE_ID)) {
31+
console.log('Todos recipe is not installed, installing now...');
32+
actions.recipe.install({ recipeId: TODOS_RECIPE_ID });
33+
}
34+
}
35+
},
36+
{
37+
fireImmediately: true,
38+
},
39+
);
3140

3241
// Toggle todos feature
3342
reaction(

src/stores/RecipesStore.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { action, computed, observable } from 'mobx';
22

3-
import Store from './lib/Store';
3+
import { matchRoute } from '../helpers/routing-helpers';
44
import CachedRequest from './lib/CachedRequest';
55
import Request from './lib/Request';
6-
import { matchRoute } from '../helpers/routing-helpers';
6+
import Store from './lib/Store';
77

88
const debug = require('debug')('Franz:RecipeStore');
99

@@ -31,6 +31,10 @@ export default class RecipesStore extends Store {
3131
return this.all;
3232
}
3333

34+
@computed get hasFinishedLoading() {
35+
return this.allRecipesRequest.wasExecuted;
36+
}
37+
3438
@computed get all() {
3539
return this.allRecipesRequest.execute().result || [];
3640
}

0 commit comments

Comments
 (0)