-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexamples.js
74 lines (68 loc) · 1.45 KB
/
examples.js
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
63
64
65
66
67
68
69
70
71
72
73
74
import {
initialState,
reduce,
type,
action,
compose,
intoArrayKey,
intoObjectKey,
intoObject
} from "src";
export const forwardHistory = reducer =>
reduce(
intoObject({
past: initialState([])(state => state.past.concat(state.present))
}),
intoObject({
present: reducer,
future: () => []
})
);
export const pushHistory = reducer =>
reduce(
intoObject({
past: initialState([])(state => state.past.concat(state.present))
}),
intoObject({
present: reducer,
future: () => []
})
);
export const backwardHistory = reduce(
intoObject({
present: state => state.past[state.past.length - 1]
}),
intoObject({
past: initialState([])(state => state.past.slice(0, -1)),
future: initialState([])(state => state.future.concat(state.present))
})
);
export const todos = initialState([])(
type({
ADD_TODO: intoArrayKey(todos => todos.length)(
intoObjectKey({
id: action("id"),
text: action("text"),
completed: ()=>false
})
),
TOGGLE_TODO: intoArrayKey((todos, action) =>
todos.findIndex(todo => todo.id === action.id)
)(
intoObjectKey({
completed: completed => !completed
})
)
})
);
export const visibility = initialState(
"SHOW_ALL" /*VisibiltyFilters.SHOW_ALL*/
)(
type({
SET_VISIBILITY_FILTER: action("filter")
})
);
export const todosApp = intoObjectKey({
todos,
visibility
});