This repository has been archived by the owner on Jul 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
tiden.js
131 lines (121 loc) · 2.69 KB
/
tiden.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import { all, fork, spawn, cancel, delay, race } from "redux-saga/effects.js"
import publish from "./lib/api/publish.js"
import cache from "./lib/api/cache.js"
import connect from "./lib/api/connect.js"
import linkTo from "./lib/api/linkTo.js"
import subscribe from "./lib/api/subscribe.js"
import merge from "./lib/api/merge.js"
import mutex from "./lib/api/mutex.js"
import once from "./lib/api/once.js"
import request from "./lib/api/request.js"
import respondTo from "./lib/api/respondTo.js"
import respondToSync from "./lib/api/respondToSync.js"
import simpleStream from "./lib/api/simpleStream.js"
import waitFor from "./lib/api/waitFor.js"
import whenChanged from "./lib/api/whenChanged.js"
import * as router from "./lib/api/routing.js"
import stream from "./lib/api/stream.js"
import render from "./lib/api/render.js"
import html from "./lib/api/html.js"
import s from "./lib/api/s.js"
import url from "./lib/url.js"
import component, {
css,
createContext,
useCallback,
useContext,
useEffect,
useLayoutEffect,
useMemo,
useReducer,
useRef,
useState,
} from "./lib/api/component.js"
function announce(...args) {
console.warn(`'announce' has been deprecated, use 'publish' instead.`)
return publish(...args)
}
function listenFor(...args) {
console.warn(`'listenFor' has been deprecated, use 'subscribe' instead.`)
return subscribe(...args)
}
export {
/* API exports starts here */
announce,
publish,
cache,
connect,
linkTo,
subscribe,
listenFor,
merge,
mutex,
once,
request,
respondTo,
respondToSync,
simpleStream,
waitFor,
whenChanged,
router,
stream,
all,
fork,
spawn,
delay,
race,
render,
cancel,
s,
url,
/* component exports start here */
component,
html,
css,
createContext,
useCallback,
useContext,
useEffect,
useLayoutEffect,
useMemo,
useReducer,
useRef,
useState,
}
import { applyMiddleware, createStore } from "redux"
import createSagaMiddleware from "redux-saga"
let sagaMiddleware
let store
export default function tiden(actor) {
if (sagaMiddleware) {
sagaMiddleware.run(actor)
return {
sagaMiddleware,
store,
}
}
const ret = {}
sagaMiddleware = createSagaMiddleware({
onError: (e, { sagaStack }) => {
console.error(e)
console.error(sagaStack)
},
})
store = createStore((s) => s || {}, applyMiddleware(sagaMiddleware))
sagaMiddleware.run(actor)
window.request = (...args) => {
sagaMiddleware.run(function* () {
const response = yield request(...args)
console.log(response)
})
}
window.publish = (...args) => {
sagaMiddleware.run(function* () {
yield publish(...args)
})
}
return {
sagaMiddleware,
store,
}
}