Skip to content

Commit 24ceb51

Browse files
committed
hotfix: type definitions in transitions/index.js, JSDoc context annotations
1 parent fce10e6 commit 24ceb51

5 files changed

Lines changed: 53 additions & 14 deletions

File tree

src/js/utils/transitions/errors.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,23 @@
44
* Error domain transitions
55
* Handles error states and recovery flows
66
*
7-
* Actions are bound to StateMachine context, so 'this' refers to the StateMachine instance
7+
* Functions are bound to StateMachine context at initialization,
8+
* so 'this' refers to the StateMachine instance.
9+
* @see state-machine.js defineTransitions() for binding logic
810
*/
911

10-
/** @type {import('./index').StateTransition[]} */
12+
/**
13+
* @typedef {import('../state-machine.js').StateTransition} StateTransition
14+
*/
15+
16+
/** @type {StateTransition[]} */
1117
export const errorTransitions = [
1218
// Generic component error - can occur from any state
1319
{
1420
event: 'ERROR',
1521
from: '*',
1622
to: 'error',
23+
/** @this {import('../state-machine.js').default} */
1724
action: function(data) {
1825
this.state.error = {
1926
code: data?.code || 'UNKNOWN_COMPONENT_ERROR',
@@ -32,6 +39,7 @@ export const errorTransitions = [
3239
event: 'FATAL_ERROR',
3340
from: '*',
3441
to: 'error',
42+
/** @this {import('../state-machine.js').default} */
3543
action: function(data) {
3644
this.state.runtimeState = 'failed';
3745
this.state.error = {
@@ -51,6 +59,7 @@ export const errorTransitions = [
5159
event: 'RETRY',
5260
from: 'error',
5361
to: 'permission',
62+
/** @this {import('../state-machine.js').default} */
5463
action: function() {
5564
this.state.error = null;
5665
this.state.runtimeState = 'idle';

src/js/utils/transitions/index.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,8 @@ import { runtimeTransitions } from './runtime.js';
66
import { errorTransitions } from './errors.js';
77

88
/**
9-
* @typedef {Object} StateTransition
10-
* @property {string} event - Event name
11-
* @property {string | '*'} from - Source state (or '*' for any state)
12-
* @property {string} to - Target state
13-
* @property {(data?: any, state?: any) => boolean} [guard] - Guard function (returns boolean)
14-
* @property {(state?: any, data?: any) => void} [action] - Side effect to execute
9+
* StateTransition type definitions are maintained in state-machine.js
10+
* @typedef {import('../state-machine.js').StateTransition} StateTransition
1511
*/
1612

1713
/**

src/js/utils/transitions/loading.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,23 @@
44
* Loading domain transitions
55
* Handles welcome screen, model loading, and warmup phases
66
*
7-
* Actions and guards are bound to StateMachine context, so 'this' refers to the StateMachine instance
7+
* Functions are bound to StateMachine context at initialization,
8+
* so 'this' refers to the StateMachine instance.
9+
* @see state-machine.js defineTransitions() for binding logic
810
*/
911

10-
/** @type {import('./index').StateTransition[]} */
12+
/**
13+
* @typedef {import('../state-machine.js').StateTransition} StateTransition
14+
*/
15+
16+
/** @type {StateTransition[]} */
1117
export const loadingTransitions = [
1218
// Welcome flow - normal path with WebGPU
1319
{
1420
event: 'START',
1521
from: 'welcome',
1622
to: 'permission',
23+
/** @this {import('../state-machine.js').default} */
1724
guard: function() {
1825
return this.state.hasWebGPU;
1926
}
@@ -24,6 +31,7 @@ export const loadingTransitions = [
2431
event: 'START_FALLBACK',
2532
from: 'welcome',
2633
to: 'image-upload',
34+
/** @this {import('../state-machine.js').default} */
2735
guard: function() {
2836
return !this.state.hasWebGPU;
2937
}
@@ -34,6 +42,7 @@ export const loadingTransitions = [
3442
event: 'WGPU_READY',
3543
from: 'loading',
3644
to: 'loading',
45+
/** @this {import('../state-machine.js').default} */
3746
action: function() {
3847
this.state.loadingPhase = 'loading-model';
3948
}
@@ -44,6 +53,7 @@ export const loadingTransitions = [
4453
event: 'MODEL_LOADED',
4554
from: 'loading',
4655
to: 'loading',
56+
/** @this {import('../state-machine.js').default} */
4757
action: function() {
4858
this.state.loadingPhase = 'warming-up';
4959
this.state.runtimeState = 'warming';
@@ -55,9 +65,11 @@ export const loadingTransitions = [
5565
event: 'WARMUP_COMPLETE',
5666
from: 'loading',
5767
to: 'runtime',
68+
/** @this {import('../state-machine.js').default} */
5869
guard: function() {
5970
return this.state.isVideoReady;
6071
},
72+
/** @this {import('../state-machine.js').default} */
6173
action: function() {
6274
this.state.loadingPhase = 'complete';
6375
this.state.runtimeState = 'running';
@@ -77,6 +89,7 @@ export const loadingTransitions = [
7789
event: 'MODEL_FAILED',
7890
from: 'loading',
7991
to: 'error',
92+
/** @this {import('../state-machine.js').default} */
8093
action: function(data) {
8194
this.state.runtimeState = 'failed';
8295
this.state.error = {

src/js/utils/transitions/permissions.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,24 @@
44
* Permission domain transitions
55
* Handles camera permission flows and related state changes
66
*
7-
* Actions are bound to StateMachine context, so 'this' refers to the StateMachine instance
7+
* Each function is bound to StateMachine context at initialization,
8+
* so 'this' refers to the StateMachine instance.
9+
* @see state-machine.js defineTransitions() for binding logic
810
*/
911

10-
/** @type {import('./index').StateTransition[]} */
12+
/**
13+
* @typedef {import('../state-machine.js').StateTransition} StateTransition
14+
*/
15+
16+
/** @type {StateTransition[]} */
1117
export const permissionsTransitions = [
1218
// Permission granted - successful camera access
1319
{
1420
event: 'PERMISSION_GRANTED',
1521
from: 'permission',
1622
to: 'loading',
1723
guard: (data) => !!data.stream,
24+
/** @this {import('../state-machine.js').default} */
1825
action: function(data) {
1926
this.state.webcamStream = data.stream;
2027
this.state.loadingPhase = 'loading-wgpu';
@@ -26,6 +33,7 @@ export const permissionsTransitions = [
2633
event: 'PERMISSION_DENIED',
2734
from: 'permission',
2835
to: 'error',
36+
/** @this {import('../state-machine.js').default} */
2937
action: function(data) {
3038
this.state.error = {
3139
code: 'CAMERA_DENIED',

src/js/utils/transitions/runtime.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,23 @@
44
* Runtime domain transitions
55
* Handles live inference execution, pause/resume, and stream recovery
66
*
7-
* Actions and guards are bound to StateMachine context, so 'this' refers to the StateMachine instance
7+
* Functions are bound to StateMachine context at initialization,
8+
* so 'this' refers to the StateMachine instance.
9+
* @see state-machine.js defineTransitions() for binding logic
810
*/
911

10-
/** @type {import('./index').StateTransition[]} */
12+
/**
13+
* @typedef {import('../state-machine.js').StateTransition} StateTransition
14+
*/
15+
16+
/** @type {StateTransition[]} */
1117
export const runtimeTransitions = [
1218
// Pause inference
1319
{
1420
event: 'PAUSE',
1521
from: 'runtime',
1622
to: 'runtime',
23+
/** @this {import('../state-machine.js').default} */
1724
action: function() {
1825
this.state.runtimeState = 'paused';
1926
}
@@ -24,6 +31,7 @@ export const runtimeTransitions = [
2431
event: 'RESUME',
2532
from: 'runtime',
2633
to: 'runtime',
34+
/** @this {import('../state-machine.js').default} */
2735
action: function() {
2836
this.state.runtimeState = 'running';
2937
}
@@ -34,6 +42,7 @@ export const runtimeTransitions = [
3442
event: 'STREAM_ENDED',
3543
from: 'runtime',
3644
to: 'runtime',
45+
/** @this {import('../state-machine.js').default} */
3746
action: function(data) {
3847
this.state.runtimeState = 'recovering';
3948
this.state.error = {
@@ -52,9 +61,11 @@ export const runtimeTransitions = [
5261
event: 'STREAM_RECOVERED',
5362
from: 'runtime',
5463
to: 'runtime',
64+
/** @this {import('../state-machine.js').default} */
5565
guard: function() {
5666
return this.state.runtimeState === 'recovering';
5767
},
68+
/** @this {import('../state-machine.js').default} */
5869
action: function(data) {
5970
this.state.webcamStream = data.stream;
6071
this.state.runtimeState = 'running';
@@ -67,9 +78,11 @@ export const runtimeTransitions = [
6778
event: 'RETRY_STREAM',
6879
from: 'runtime',
6980
to: 'permission',
81+
/** @this {import('../state-machine.js').default} */
7082
guard: function() {
7183
return this.state.runtimeState === 'recovering';
7284
},
85+
/** @this {import('../state-machine.js').default} */
7386
action: function() {
7487
// Stop existing dead stream
7588
if (this.state.webcamStream) {

0 commit comments

Comments
 (0)