@@ -5,14 +5,26 @@ import { Observable, of } from 'rxjs';
5
5
import { catchError , map , mergeMap } from 'rxjs/operators' ;
6
6
import { Color } from '../shared/color.interfaces' ;
7
7
import {
8
+ ADD_TOPIC ,
9
+ AddTopic ,
10
+ AddTopicFailed ,
11
+ AddTopicSuccess ,
12
+ DELETE_TASK ,
13
+ DeleteTask ,
14
+ DeleteTaskFailed ,
15
+ DeleteTaskSuccess ,
8
16
GET_MATRIX_DATA ,
9
17
GetMatrixData ,
10
18
GetMatrixDataFailed ,
11
19
GetMatrixDataSuccess ,
12
20
UPDATE_TASK ,
21
+ UPDATE_TOPIC ,
13
22
UpdateTask ,
14
23
UpdateTaskFailed ,
15
24
UpdateTaskSuccess ,
25
+ UpdateTopic ,
26
+ UpdateTopicFailed ,
27
+ UpdateTopicSuccess ,
16
28
} from './matrix.actions' ;
17
29
import { MatrixData , Task , Topic } from './matrix.interfaces' ;
18
30
@@ -62,4 +74,61 @@ export class MatrixEffects {
62
74
) ,
63
75
) ,
64
76
) ;
77
+
78
+ @Effect ( )
79
+ deleteTask$ : Observable < Action > = this . actions$ . pipe (
80
+ ofType < DeleteTask > ( DELETE_TASK ) ,
81
+ mergeMap ( ( action ) =>
82
+ of ( action . taskId ) . pipe (
83
+ map (
84
+ ( taskId : number ) =>
85
+ new DeleteTaskSuccess (
86
+ new Task (
87
+ taskId ,
88
+ 'deleted' ,
89
+ 1 ,
90
+ 1 ,
91
+ 1 ,
92
+ 1 ,
93
+ 21 ,
94
+ '' ,
95
+ false ,
96
+ true ,
97
+ undefined ,
98
+ undefined ,
99
+ new Date ( ) ,
100
+ ) ,
101
+ ) ,
102
+ ) ,
103
+ catchError ( ( message ) => of ( new DeleteTaskFailed ( message ) ) ) ,
104
+ ) ,
105
+ ) ,
106
+ ) ;
107
+
108
+ @Effect ( )
109
+ addTopic$ : Observable < Action > = this . actions$ . pipe (
110
+ ofType < AddTopic > ( ADD_TOPIC ) ,
111
+ mergeMap ( ( action ) =>
112
+ of ( Math . floor ( Math . random ( ) * ( 100 - 4 ) - 4 ) ) . pipe (
113
+ map (
114
+ ( id : number ) =>
115
+ new AddTopicSuccess (
116
+ new Topic ( id , 'New Topic' , Color . green , true , false ) ,
117
+ ) ,
118
+ ) ,
119
+ catchError ( ( message ) => of ( new AddTopicFailed ( message ) ) ) ,
120
+ ) ,
121
+ ) ,
122
+ ) ;
123
+
124
+ @Effect ( )
125
+ updateTopic$ : Observable < Action > = this . actions$ . pipe (
126
+ ofType < UpdateTopic > ( UPDATE_TOPIC ) ,
127
+ mergeMap ( ( action ) =>
128
+ of ( action . topic ) . pipe (
129
+ map ( ( topic : Topic ) => new UpdateTopicSuccess ( topic ) ) ,
130
+ catchError ( ( message ) => of ( new UpdateTopicFailed ( message ) ) ) ,
131
+ ) ,
132
+ ) ,
133
+ ) ;
65
134
}
0 commit comments