mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-01 11:50:54 +08:00
Add State Machine definitions and tests
This commit is contained in:
@@ -23,6 +23,7 @@ Complete
|
||||
* [ember.js](http://emberjs.com/) (by [Boris Yankov](https://github.com/borisyankov))
|
||||
* [Express](http://expressjs.com/) (by [Boris Yankov](https://github.com/borisyankov))
|
||||
* [Fancybox](http://fancybox.net/) (by [Boris Yankov](https://github.com/borisyankov))
|
||||
* [Finite State Machine](https://github.com/jakesgordon/javascript-state-machine) (by [Boris Yankov](https://github.com/borisyankov))
|
||||
* [Foundation](http://foundation.zurb.com/) (by [Boris Yankov](https://github.com/borisyankov))
|
||||
* [GoogleMaps](https://developers.google.com/maps/) (by [Esben Nepper](https://github.com/eNepper))
|
||||
* [Handlebars](http://handlebarsjs.com/) (by [Boris Yankov](https://github.com/borisyankov))
|
||||
|
||||
Vendored
+49
@@ -0,0 +1,49 @@
|
||||
// Type definitions for Finite State Machine 2.2
|
||||
// Project: https://github.com/jakesgordon/javascript-state-machine
|
||||
// Definitions by: Boris Yankov <https://github.com/borisyankov/>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
|
||||
interface ErrorCallback {
|
||||
(name: string, from: string, to: string, args: any[]): void;
|
||||
}
|
||||
|
||||
interface EventCallback {
|
||||
event: string;
|
||||
from: string;
|
||||
to: string;
|
||||
msg?: string;
|
||||
}
|
||||
|
||||
interface StateMachineEvent {
|
||||
name: string;
|
||||
from: string;
|
||||
to: string;
|
||||
}
|
||||
|
||||
interface StateMachineConfig {
|
||||
initial?: any; // string or { state: 'foo', event: 'setup', defer: true|false }
|
||||
events?: StateMachineEvent[];
|
||||
callbacks?: any;
|
||||
target?: any;
|
||||
error?: ErrorCallback;
|
||||
}
|
||||
|
||||
interface StateMachineStatic {
|
||||
create(config: StateMachineConfig, target?: any): StateMachine;
|
||||
}
|
||||
|
||||
interface StateMachine {
|
||||
current: string;
|
||||
is(sstate: string): bool;
|
||||
can(event: StateMachineEvent): bool;
|
||||
cannot(event: StateMachineEvent): bool;
|
||||
error: ErrorCallback;
|
||||
|
||||
onbeforeevent: EventCallback;
|
||||
onleaveevent: EventCallback;
|
||||
onenterevent: EventCallback;
|
||||
onafterevent: EventCallback;
|
||||
}
|
||||
|
||||
declare var StateMachine: StateMachineStatic;
|
||||
@@ -0,0 +1,18 @@
|
||||
/// <reference path="state-machine-2.2.d.ts" />
|
||||
|
||||
var fsm = StateMachine.create({
|
||||
initial: 'green',
|
||||
events: [
|
||||
{ name: 'warn', from: 'green', to: 'yellow' },
|
||||
{ name: 'panic', from: 'yellow', to: 'red' },
|
||||
{ name: 'calm', from: 'red', to: 'yellow' },
|
||||
{ name: 'clear', from: 'yellow', to: 'green' }
|
||||
],
|
||||
callbacks: {
|
||||
onpanic: function (event, from, to, msg) { alert('panic! ' + msg); },
|
||||
onclear: function (event, from, to, msg) { alert('thanks to ' + msg); },
|
||||
ongreen: function (event, from, to) { document.body.className = 'green'; },
|
||||
onyellow: function (event, from, to) { document.body.className = 'yellow'; },
|
||||
onred: function (event, from, to) { document.body.className = 'red'; },
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user