Skip to content

Commit 778dee5

Browse files
committed
Add build artifacts
1 parent 5aa6485 commit 778dee5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+9905
-3
lines changed

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ node_modules
2929
# Other
3030
.DS_Store
3131
.vscode/
32-
dist/
33-
lib/
34-
es/
32+
# dist/
33+
# lib/
34+
# es/
3535
editor/
3636
examples/
3737
_examples/

dist/xstate.graph.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/xstate.interpreter.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/xstate.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

es/Machine.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import { StateMachine, MachineOptions, DefaultContext, MachineConfig, StateSchema, EventObject } from './types';
2+
export declare function Machine<TContext = DefaultContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = EventObject>(config: MachineConfig<TContext, TStateSchema, TEvent>, options?: MachineOptions<TContext, TEvent>, initialContext?: TContext | undefined): StateMachine<TContext, TStateSchema, TEvent>;

es/Machine.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { StateNode } from './StateNode';
2+
export function Machine(config, options, initialContext) {
3+
if (initialContext === void 0) {
4+
initialContext = config.context;
5+
}
6+
return new StateNode(config, options, initialContext);
7+
}

es/State.d.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { StateValue, ActivityMap, EventObject, StateInterface, HistoryValue, ActionObject, EventType, StateConfig } from './types';
2+
import { StateTree } from './StateTree';
3+
export declare function stateValuesEqual(a: StateValue, b: StateValue): boolean;
4+
export declare class State<TContext, TEvent extends EventObject = EventObject> implements StateInterface<TContext> {
5+
value: StateValue;
6+
context: TContext;
7+
historyValue?: HistoryValue | undefined;
8+
history?: State<TContext>;
9+
actions: Array<ActionObject<TContext>>;
10+
activities: ActivityMap;
11+
meta: any;
12+
events: TEvent[];
13+
/**
14+
* The state node tree representation of the state value.
15+
*/
16+
tree?: StateTree;
17+
/**
18+
* Creates a new State instance for the given `stateValue` and `context`.
19+
* @param stateValue
20+
* @param context
21+
*/
22+
static from<TC, TE extends EventObject = EventObject>(stateValue: State<TC, TE> | StateValue, context: TC): State<TC, TE>;
23+
/**
24+
* Creates a new State instance for the given `config`.
25+
* @param config The state config
26+
*/
27+
static create<TC, TE extends EventObject = EventObject>(config: StateConfig<TC, TE>): State<TC, TE>;
28+
/**
29+
* Creates a new State instance for the given `stateValue` and `context` with no actions (side-effects).
30+
* @param stateValue
31+
* @param context
32+
*/
33+
static inert<TC, TE extends EventObject = EventObject>(stateValue: State<TC> | StateValue, context: TC): State<TC, TE>;
34+
/**
35+
* Creates a new State instance.
36+
* @param value The state value
37+
* @param context The extended state
38+
* @param historyValue The tree representing historical values of the state nodes
39+
* @param history The previous state
40+
* @param actions An array of action objects to execute as side-effects
41+
* @param activities A mapping of activities and whether they are started (`true`) or stopped (`false`).
42+
* @param meta
43+
* @param events Internal event queue. Should be empty with run-to-completion semantics.
44+
* @param tree
45+
*/
46+
constructor(config: StateConfig<TContext, TEvent>);
47+
/**
48+
* The next events that will cause a transition from the current state.
49+
*/
50+
readonly nextEvents: EventType[];
51+
/**
52+
* Returns an array of all the string leaf state node paths.
53+
* @param stateValue
54+
* @param delimiter The character(s) that separate each subpath in the string state node path.
55+
*/
56+
toStrings(stateValue?: StateValue, delimiter?: string): string[];
57+
/**
58+
* Whether the current state value is a subset of the given parent state value.
59+
* @param parentStateValue
60+
*/
61+
matches(parentStateValue: StateValue): boolean;
62+
/**
63+
* Indicates whether the state has changed from the previous state. A state is considered "changed" if:
64+
*
65+
* - Its value is not equal to its previous value, or:
66+
* - It has any new actions (side-effects) to execute.
67+
*
68+
* An initial state (with no history) will return `undefined`.
69+
*/
70+
readonly changed: boolean | undefined;
71+
}

es/State.js

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
var __read = this && this.__read || function (o, n) {
2+
var m = typeof Symbol === "function" && o[Symbol.iterator];
3+
if (!m) return o;
4+
var i = m.call(o),
5+
r,
6+
ar = [],
7+
e;
8+
try {
9+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
10+
} catch (error) {
11+
e = { error: error };
12+
} finally {
13+
try {
14+
if (r && !r.done && (m = i["return"])) m.call(i);
15+
} finally {
16+
if (e) throw e.error;
17+
}
18+
}
19+
return ar;
20+
};
21+
var __spread = this && this.__spread || function () {
22+
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
23+
return ar;
24+
};
25+
import { EMPTY_ACTIVITY_MAP } from './constants';
26+
import { matchesState, keys } from './utils';
27+
export function stateValuesEqual(a, b) {
28+
if (a === b) {
29+
return true;
30+
}
31+
var aKeys = keys(a);
32+
var bKeys = keys(b);
33+
return aKeys.length === bKeys.length && aKeys.every(function (key) {
34+
return stateValuesEqual(a[key], b[key]);
35+
});
36+
}
37+
var State = /** @class */ /*#__PURE__*/function () {
38+
/**
39+
* Creates a new State instance.
40+
* @param value The state value
41+
* @param context The extended state
42+
* @param historyValue The tree representing historical values of the state nodes
43+
* @param history The previous state
44+
* @param actions An array of action objects to execute as side-effects
45+
* @param activities A mapping of activities and whether they are started (`true`) or stopped (`false`).
46+
* @param meta
47+
* @param events Internal event queue. Should be empty with run-to-completion semantics.
48+
* @param tree
49+
*/
50+
function State(config) {
51+
this.actions = [];
52+
this.activities = EMPTY_ACTIVITY_MAP;
53+
this.meta = {};
54+
this.events = [];
55+
this.value = config.value;
56+
this.context = config.context;
57+
this.historyValue = config.historyValue;
58+
this.history = config.history;
59+
this.actions = config.actions || [];
60+
this.activities = config.activities || EMPTY_ACTIVITY_MAP;
61+
this.meta = config.meta || {};
62+
this.events = config.events || [];
63+
Object.defineProperty(this, 'tree', {
64+
value: config.tree,
65+
enumerable: false
66+
});
67+
}
68+
/**
69+
* Creates a new State instance for the given `stateValue` and `context`.
70+
* @param stateValue
71+
* @param context
72+
*/
73+
State.from = function (stateValue, context) {
74+
if (stateValue instanceof State) {
75+
if (stateValue.context !== context) {
76+
return new State({
77+
value: stateValue.value,
78+
context: context,
79+
historyValue: stateValue.historyValue,
80+
history: stateValue.history,
81+
actions: [],
82+
activities: stateValue.activities,
83+
meta: {},
84+
events: [],
85+
tree: stateValue.tree
86+
});
87+
}
88+
return stateValue;
89+
}
90+
return new State({
91+
value: stateValue,
92+
context: context,
93+
historyValue: undefined,
94+
history: undefined,
95+
actions: [],
96+
activities: undefined,
97+
meta: undefined,
98+
events: []
99+
});
100+
};
101+
/**
102+
* Creates a new State instance for the given `config`.
103+
* @param config The state config
104+
*/
105+
State.create = function (config) {
106+
return new State(config);
107+
};
108+
/**
109+
* Creates a new State instance for the given `stateValue` and `context` with no actions (side-effects).
110+
* @param stateValue
111+
* @param context
112+
*/
113+
State.inert = function (stateValue, context) {
114+
if (stateValue instanceof State) {
115+
if (!stateValue.actions.length) {
116+
return stateValue;
117+
}
118+
return new State({
119+
value: stateValue.value,
120+
context: context,
121+
historyValue: stateValue.historyValue,
122+
history: stateValue.history,
123+
activities: stateValue.activities,
124+
tree: stateValue.tree
125+
});
126+
}
127+
return State.from(stateValue, context);
128+
};
129+
Object.defineProperty(State.prototype, "nextEvents", {
130+
/**
131+
* The next events that will cause a transition from the current state.
132+
*/
133+
get: function () {
134+
if (!this.tree) {
135+
return [];
136+
}
137+
return this.tree.nextEvents;
138+
},
139+
enumerable: true,
140+
configurable: true
141+
});
142+
/**
143+
* Returns an array of all the string leaf state node paths.
144+
* @param stateValue
145+
* @param delimiter The character(s) that separate each subpath in the string state node path.
146+
*/
147+
State.prototype.toStrings = function (stateValue, delimiter) {
148+
var _this = this;
149+
if (stateValue === void 0) {
150+
stateValue = this.value;
151+
}
152+
if (delimiter === void 0) {
153+
delimiter = '.';
154+
}
155+
if (typeof stateValue === 'string') {
156+
return [stateValue];
157+
}
158+
var valueKeys = keys(stateValue);
159+
return valueKeys.concat.apply(valueKeys, __spread(valueKeys.map(function (key) {
160+
return _this.toStrings(stateValue[key]).map(function (s) {
161+
return key + delimiter + s;
162+
});
163+
})));
164+
};
165+
/**
166+
* Whether the current state value is a subset of the given parent state value.
167+
* @param parentStateValue
168+
*/
169+
State.prototype.matches = function (parentStateValue) {
170+
return matchesState(parentStateValue, this.value);
171+
};
172+
Object.defineProperty(State.prototype, "changed", {
173+
/**
174+
* Indicates whether the state has changed from the previous state. A state is considered "changed" if:
175+
*
176+
* - Its value is not equal to its previous value, or:
177+
* - It has any new actions (side-effects) to execute.
178+
*
179+
* An initial state (with no history) will return `undefined`.
180+
*/
181+
get: function () {
182+
if (!this.history) {
183+
return undefined;
184+
}
185+
return !!this.actions.length || (typeof this.history.value !== typeof this.value ? true : typeof this.value === 'string' ? this.value !== this.history.value : stateValuesEqual(this.value, this.history.value));
186+
},
187+
enumerable: true,
188+
configurable: true
189+
});
190+
return State;
191+
}();
192+
export { State };

0 commit comments

Comments
 (0)