MCPcopy
hub / github.com/statelyai/xstate / constructor

Method constructor

packages/core/src/StateNode.ts:149–220  ·  view source on GitHub ↗
(
    /** The raw config used to create the machine. */
    public config: StateNodeConfig<
      TContext,
      TEvent,
      TODO, // actors
      TODO, // actions
      TODO, // guards
      TODO, // delays
      TODO, // tags
      TODO, // output
      TODO, // emitted
      TODO // meta
    >,
    options: StateNodeOptions<TContext, TEvent>
  )

Source from the content-addressed store, hash-verified

147 public always?: Array<TransitionDefinition<TContext, TEvent>>;
148
149 constructor(
150 /** The raw config used to create the machine. */
151 public config: StateNodeConfig<
152 TContext,
153 TEvent,
154 TODO, // actors
155 TODO, // actions
156 TODO, // guards
157 TODO, // delays
158 TODO, // tags
159 TODO, // output
160 TODO, // emitted
161 TODO // meta
162 >,
163 options: StateNodeOptions<TContext, TEvent>
164 ) {
165 this.parent = options._parent;
166 this.key = options._key;
167 this.machine = options._machine;
168 this.path = this.parent ? this.parent.path.concat(this.key) : [];
169 this.id =
170 this.config.id || [this.machine.id, ...this.path].join(STATE_DELIMITER);
171 this.type =
172 this.config.type ||
173 (this.config.states && Object.keys(this.config.states).length
174 ? 'compound'
175 : this.config.history
176 ? 'history'
177 : 'atomic');
178 this.description = this.config.description;
179
180 this.order = this.machine.idMap.size;
181 this.machine.idMap.set(this.id, this);
182
183 this.states = (
184 this.config.states
185 ? mapValues(
186 this.config.states,
187 (stateConfig: AnyStateNodeConfig, key) => {
188 const stateNode = new StateNode(stateConfig, {
189 _parent: this,
190 _key: key,
191 _machine: this.machine
192 });
193 return stateNode;
194 }
195 )
196 : EMPTY_OBJECT
197 ) as StateNodesConfig<TContext, TEvent>;
198
199 if (this.type === 'compound' && !this.config.initial) {
200 throw new Error(
201 `No initial state specified for compound state node "#${
202 this.id
203 }". Try adding { initial: "${
204 Object.keys(this.states)[0]
205 }" } to the state config.`
206 );

Callers

nothing calls this directly

Calls 3

mapValuesFunction · 0.90
toArrayFunction · 0.90
setMethod · 0.65

Tested by

no test coverage detected