-
Notifications
You must be signed in to change notification settings - Fork 780
/
index.js
34 lines (29 loc) · 841 Bytes
/
index.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
const timeout = (dispatch, props) =>
setTimeout(() => dispatch(props.action), props.delay)
const interval = (dispatch, props) => {
const id = setInterval(() => {
dispatch(props.action, Date.now())
}, props.delay)
return () => clearInterval(id)
}
const getTime = (dispatch, props) => dispatch(props.action, Date.now())
/**
* @example
* app({
* subscriptions: (state) => [
* // Dispatch RequestResource every delayInMilliseconds
* every(state.delayInMilliseconds, RequestResource),
* ],
* })
*/
export const every = (delay, action) => [interval, { delay, action }]
/**
* @example
* const SlowClap = (state, ms = 1200) => [state, delay(ms, Clap)]
*/
export const delay = (delay, action) => [timeout, { delay, action }]
/**
* @example
* now(NewTime)
*/
export const now = (action) => [getTime, { action }]