-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
46 lines (36 loc) · 1021 Bytes
/
index.ts
File metadata and controls
46 lines (36 loc) · 1021 Bytes
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
import { combine, create, resolve, value } from "@submodule/core"
const seed = value(0)
const algo = value((n: number) => n + 1)
const getNextId = create(({ seed, algo}) => {
let current = seed
return () => {
current = algo(current)
return current
}
}, combine({
seed, algo
}))
const currentDate = create(() => new Date())
const getCurrentDate = create((date) => {
return () => date
}, currentDate)
const make = create(({ getNextId, getCurrentDate }) => {
const nextId = getNextId()
const createdDate = getCurrentDate()
// ....
}, combine({ getNextId, getCurrentDate }))
const anotherCreate = create(({ getNextId }) => {
const nextId = getNextId()
// ...
}, combine({ getNextId }))
const anotherUseDate = create(({ getCurrentDate }) => {
const createdDate = getCurrentDate()
// ...
}, combine({ getCurrentDate }))
async function run() {
await resolve(make)
}
async function testAnotherCreate() {
anotherCreate.patch(algo, value(n => n * 2))
await resolve(anotherCreate)
}