Skip to content

Commit 66e9ce2

Browse files
committed
Add jsdocs
1 parent cb5d711 commit 66e9ce2

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

worker.js

+24-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createMachine, interpret } from 'xstate'
1+
import { Interpreter, MachineConfig, StateMachine, StateValue, State as XState, createMachine, interpret } from 'xstate'
22

33
export default {
44
fetch: (req, env) => {
@@ -9,7 +9,7 @@ export default {
99
'Access-Control-Allow-Credentials': 'true',
1010
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
1111
'Access-Control-Allow-Headers': 'Content-Type, Authorization, Cookie, X-Forwarded-Proto, X-Forwarded-For',
12-
'Access-Control-Max-Age': 86400,
12+
'Access-Control-Max-Age': '86400',
1313
},
1414
})
1515
}
@@ -22,6 +22,19 @@ export default {
2222
}
2323

2424
export class State {
25+
state
26+
env
27+
/** @type {MachineConfig} */
28+
machineDefinition
29+
/** @type {StateValue} */
30+
machineState
31+
/** @type {StateMachine} */
32+
machine
33+
/** @type {Interpreter} */
34+
service
35+
/** @type {XState} */
36+
serviceState
37+
2538
constructor(state, env) {
2639
this.state = state
2740
this.env = env
@@ -33,6 +46,9 @@ export class State {
3346
})
3447
}
3548

49+
/**
50+
* @param {StateValue|undefined} state
51+
*/
3652
startMachine(state) {
3753
this.machine = createMachine(this.machineDefinition)
3854
this.service = interpret(this.machine)
@@ -80,6 +96,9 @@ export class State {
8096
if (this.machineDefinition) this.startMachine()
8197
}
8298

99+
/**
100+
* @param {MachineConfig} machineDefinition
101+
*/
83102
async update(machineDefinition) {
84103
// Don't update if the new definition is empty or hasn't changed
85104
if (!machineDefinition || machineDefinition === this.machineDefinition) return
@@ -88,6 +107,9 @@ export class State {
88107
this.startMachine(this.machineState)
89108
}
90109

110+
/**
111+
* @param {Request} req
112+
*/
91113
async fetch(req) {
92114
let { user, redirect, method, origin, pathSegments, search, json } = await this.env.CTX.fetch(req).then((res) => res.json())
93115
if (redirect) return Response.redirect(redirect)

0 commit comments

Comments
 (0)