forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathredux-action-utils-tests.ts
62 lines (50 loc) · 1.41 KB
/
redux-action-utils-tests.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/// <reference path="redux-action-utils.d.ts" />
/// <reference path="../redux/redux.d.ts" />
import { actionCreator, optionsActionCreator } from 'redux-action-utils';
import { Action, ActionCreator } from 'redux-action-utils';
let types = {
ADD_LESSON: 'ADD_LESSON',
IMPORT_LESSONS: 'IMPORT_LESSONS',
UPDATE_LESSON: 'UPDATE_LESSON'
};
var type: string;
export default {
addLesson: actionCreator(types.ADD_LESSON),
importLessons: actionCreator(types.IMPORT_LESSONS, 'lessons'),
updateLesson: optionsActionCreator(types.UPDATE_LESSON, 'id', 'update')
};
var ac = actionCreator(types.ADD_LESSON);
var action: Action = ac();
type = action.type;
class ImportLesson {
lessons: string[];
}
const importLessonAction = actionCreator<ImportLesson>(types.IMPORT_LESSONS, 'lessons');
var importLesson = importLessonAction(['lesson 1', 'lesson 2']);
// → {type: 'IMPORT_LESSONS', lessons: ['lesson 1', 'lesson 2']}
var lessons: string[] = importLesson.lessons;
type = importLesson.type;
class UpdateLesson {
id: number;
update: {
text: string
}
}
const updateLessonAction = optionsActionCreator<UpdateLesson>(types.UPDATE_LESSON, 'id', 'update');
let updateLesson = updateLessonAction({
id: 1,
update: {
text: '## Lesson 1'
}
});
/* →
{
type: 'UPDATE_LESSON',
id: 1,
update: {
text: '## Lesson 1'
}
}
*/
let id: number = updateLesson.id;
type = updateLesson.type;