Skip to content

Commit

Permalink
Merge 993f1d3 into b9511fd
Browse files Browse the repository at this point in the history
  • Loading branch information
mrnerdhair committed Jun 7, 2018
2 parents b9511fd + 993f1d3 commit 3bf81f0
Show file tree
Hide file tree
Showing 46 changed files with 7,805 additions and 6,028 deletions.
11 changes: 8 additions & 3 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
{
"presets": [
["es2015", {
["env", {
"targets": {
"node": "8.0",
"browsers": "Chrome >= 62, Firefox >= 59, Edge >= 16, iOS >= 10.3, Safari >= 10.1"
},
"loose": true,
}],
"stage-0"
"useBuiltIns": true,
"debug": true
}]
],
"ignore": [
"src/index.commonjs.js"
Expand Down
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"extends": "airbnb/base",
"parser": "babel-eslint",
"env": {
"node": true,
"jasmine": true
Expand Down Expand Up @@ -32,5 +31,7 @@
"arrow-parens": ["error", "as-needed"],
"function-paren-newline": "off",
"prefer-destructuring": "off",
"no-return-await": "off",
"no-return-assign": ["error", "except-parens"]
}
}
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.js text eol=lf
*.ts text eol=lf
*.json text eol=lf
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ umd/
node_modules/
typings/
coverage/
.nyc_output/
npm-debug.log
.DS_Store
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ src/
test/
examples/
coverage/
.nyc_output/
node_modules/
typings/
npm-debug.log
Expand Down
5 changes: 1 addition & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ cache:
directories:
- node_modules
script:
- npm run lint
- npm run build
- npm run coverage
- npm run test:typings
- npm run test:full
after_success:
- cat coverage/lcov.info | node_modules/coveralls/bin/coveralls.js
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [

{
"type": "node",
"request": "launch",
"name": "Run Tests",
"program": "${workspaceFolder}\\test\\support\\jasmineRunner.js"
}
]
}
3 changes: 2 additions & 1 deletion ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
- [x] Promise triggers
- [x] Hierarchical state machines
- [x] Ignoring events
- [ ] Async transitions *(in progress)*
- [x] Async transitions
- [ ] Persistence support

## Documentation
Expand All @@ -21,3 +21,4 @@
- [ ] Execution order of entry, exit, and transition actions and global hooks
- [ ] Recursive events & event queue
- [ ] API reference
- [ ] Async transitions
20 changes: 10 additions & 10 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
declare const Finity: {
configure(): StateMachineConfigurator<string, string>;
configure<S, E>(): StateMachineConfigurator<S, E>;
start<S, E>(config: Configuration<S, E>): StateMachine<S, E>;
start<S, E>(config: Configuration<S, E>): Promise<StateMachine<S, E>>;
};

export default Finity;
Expand All @@ -14,12 +14,12 @@ export interface StateMachineConfigurator<S, E> extends BaseConfigurator<S, E> {
global(): GlobalConfigurator<S, E>;
initialState(state: S): StateConfigurator<S, E>;
state(state: S): StateConfigurator<S, E>;
start(): StateMachine<S, E>;
start(): Promise<StateMachine<S, E>>;
}

export type StateHook<S, E> = (state: S, context: Context<S, E>) => void;
export type TransitionHook<S, E> = (fromState: S, toState: S, context: Context<S, E>) => void;
export type UnhandledEventHook<S, E> = (event: E, state: S, context: Context<S, E>) => void;
export type StateHook<S, E> = (state: S, context: Context<S, E>) => void | Promise<void>;
export type TransitionHook<S, E> = (fromState: S, toState: S, context: Context<S, E>) => void | Promise<void>;
export type UnhandledEventHook<S, E> = (event: E, state: S, context: Context<S, E>) => void | Promise<void>;

export interface GlobalConfigurator<S, E> extends BaseConfigurator<S, E>, StateMachineConfigurator<S, E> {
onStateEnter(hook: StateHook<S, E>): GlobalConfigurator<S, E>;
Expand All @@ -29,7 +29,7 @@ export interface GlobalConfigurator<S, E> extends BaseConfigurator<S, E>, StateM
onUnhandledEvent(hook: UnhandledEventHook<S, E>): GlobalConfigurator<S, E>;
}

export type StateAction<S, E> = (state: S, context: Context<S, E>) => void;
export type StateAction<S, E> = (state: S, context: Context<S, E>) => void | Promise<void>;

export type AsyncOperation<S, E> = (state: S, context: Context<S, E>) => Promise<any>;

Expand Down Expand Up @@ -58,8 +58,8 @@ export interface AsyncConfigurator<S, E> extends BaseConfigurator<S, E> {
onFailure(): TriggerConfigurator<S, E>;
}

export type TransitionAction<S, E> = (fromState: S, toState: S, context: Context<S, E>) => void;
export type Condition<S, E> = (context: Context<S, E>) => boolean;
export type TransitionAction<S, E> = (fromState: S, toState: S, context: Context<S, E>) => void | Promise<void>;
export type Condition<S, E> = (context: Context<S, E>) => boolean | Promise<boolean>;

export interface TransitionConfigurator<S, E>
extends BaseConfigurator<S, E>, StateConfigurator<S, E>, TriggerConfigurator<S, E>, AsyncConfigurator<S, E> {
Expand All @@ -73,8 +73,8 @@ export interface Configuration<S, E> {
export interface StateMachine<S, E> {
getCurrentState(): S;
getStateHierarchy(): S[];
canHandle(event: E, eventPayload?: any): boolean;
handle(event: E, eventPayload?: any): StateMachine<S, E>;
canHandle(event: E, eventPayload?: any): Promise<boolean>;
handle(event: E, eventPayload?: any): Promise<any>;
}

export interface Context<S, E> {
Expand Down

0 comments on commit 3bf81f0

Please sign in to comment.