-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathtest.js
90 lines (80 loc) · 2.1 KB
/
test.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import test from "ava"
import { createStore, applyMiddleware } from "redux"
import { pipe, filter, forEach, map } from "callbag-basics"
import createCallbagMiddleware from "./dist/redux-callbag"
import delay from "callbag-delay"
const todos = (state = [], action) => {
switch (action.type) {
case "ADD_TODO":
return state.concat([action.payload])
case "REMOVE_TODO":
return []
case "ADD_SOMETHING":
return state.concat([action.payload])
case "AAAAA":
console.log(action)
return state
default:
return state
}
}
const addTodo = payload => {
return {
type: "ADD_TODO",
payload
}
}
const addSomething = payload => {
return {
type: "ADD_SOMETHING",
payload
}
}
const removeTodo = () => {
return {
type: "REMOVE_TODO"
}
}
const store = createStore(
todos,
["Hello world"],
applyMiddleware(
createCallbagMiddleware((actions, store) => {
const { select, mapSuccessTo, mapPromise } = actions
actions |> select() |> mapPromise(d => 123) |> mapSuccessTo("AAAAA")
actions
|> select("ADD_SOMETHING")
|> delay(1000)
|> forEach(({ payload }) => {
console.log("log:" + payload)
})
actions
|> select("ADD_TODO")
|> delay(1000)
|> mapSuccessTo(
"ADD_SOMETHING",
payload => payload + " 23333333"
)
})
)
)
store.dispatch(addTodo("Hello redux"))
store.dispatch(addSomething("This will not add numbers"))
test("sync", t => {
t.deepEqual(store.getState(), [
"Hello world",
"Hello redux",
"This will not add numbers"
])
})
test.cb("async", t => {
store.subscribe(() => {
t.deepEqual(store.getState(), [
"Hello world",
"Hello redux",
"This will not add numbers",
"Hello redux 23333333"
])
t.end()
})
})