Skip to content

Commit ac2f687

Browse files
committed
fix(todoApp): fixed todo initialization
1 parent 43605b1 commit ac2f687

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

src/feature-b/feature-b.config.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ export function routing($stateProvider) {
33
$stateProvider
44
.state('app.feature-b', {
55
url: '/feature-b',
6-
template: '<div todo-component></div>'
6+
template: '<div todo-component></div>',
7+
resolve: {
8+
initialTodos: function() {
9+
return [];
10+
}
11+
}
712
});
813
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export const EMPTY_TODOS = [];
2+
3+
export const DEFAULT_TODOS = [
4+
{ label: 'Read blog post', done: true },
5+
{ label: 'Checkout from github & run example', done: true },
6+
{ label: 'Check github repository for implementation details', done: false },
7+
{ label: 'Use in your own project!', done: false }
8+
];

src/feature-b/feature-b.module.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import angular from 'angular';
22
import uirouter from 'angular-ui-router';
33

44
import { routing } from './feature-b.config.js';
5+
import { EMPTY_TODOS, DEFAULT_TODOS } from './feature-b.constants.js';
56

67
import todoComponent from './todo-component/todo-component.directive';
78
import TodoService from './services/todo.service';
@@ -12,4 +13,5 @@ export default angular
1213
.config(routing)
1314
.directive('todoComponent', todoComponent)
1415
.factory('TodoService', TodoService)
16+
.constant('initialTodos', DEFAULT_TODOS)
1517
.name;

src/feature-b/services/todo.service.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,7 @@ import * as _ from 'lodash';
22

33
export default function TodoService(initialTodos) {
44

5-
const defaultTodos = [
6-
{ label: 'Read blog post', done: true },
7-
{ label: 'Checkout from github & run example', done: true },
8-
{ label: 'Check github repository for implementation details', done: false },
9-
{ label: 'Use in your own project!', done: false }
10-
];
11-
12-
const todos = initialTodos || defaultTodos;
5+
const todos = initialTodos;
136

147
return {
158
todos,

0 commit comments

Comments
 (0)