MCPcopy Index your code
hub / github.com/webpack/webpack-dev-server / createMachine

Function createMachine

client-src/overlay.js:119–148  ·  view source on GitHub ↗

* A simplified `createMachine` from `@xstate/fsm` with the following differences: * - the returned machine is technically a "service". No `interpret(machine).start()` is needed. * - the state definition only support `on` and target must be declared with { target: 'nextState', actions: [] } explici

({ states, context, initial }, { actions })

Source from the content-addressed store, hash-verified

117 * @returns {StateMachine} state machine
118 */
119function createMachine({ states, context, initial }, { actions }) {
120 let currentState = initial;
121 let currentContext = context;
122
123 return {
124 send: (event) => {
125 const currentStateOn = states[currentState].on;
126 const transitionConfig = currentStateOn && currentStateOn[event.type];
127
128 if (transitionConfig) {
129 currentState = transitionConfig.target;
130 if (transitionConfig.actions) {
131 transitionConfig.actions.forEach((actName) => {
132 const actionImpl = actions[actName];
133
134 const nextContextValue =
135 actionImpl && actionImpl(currentContext, event);
136
137 if (nextContextValue) {
138 currentContext = {
139 ...currentContext,
140 ...nextContextValue,
141 };
142 }
143 });
144 }
145 }
146 },
147 };
148}
149
150/**
151 * @typedef {object} ShowOverlayData

Callers 1

createOverlayMachineFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…