taoqf / javascript-state-machine Goto Github PK
View Code? Open in Web Editor NEWThis project forked from jakesgordon/javascript-state-machine
A javascript finite state machine library
License: MIT License
This project forked from jakesgordon/javascript-state-machine
A javascript finite state machine library
License: MIT License
Can anyone help me with that:
var FSM = StateMachine.factory({
init: 'A',
transitions: [{
name: 'step',
from: 'A',
to: 'B'
}, {
name: 'step',
from: 'B',
to: 'C'
}]
});
var fsm1 = new FSM();
fsm1.goto('B');
I'm getting the following error:
fsm1.goto('B');
^
TypeError: fsm1.goto is not a function
$ node -v
$ v8.2.0
According to the docs, the following behavior is incorrect: when the onBeforeTransition
function returns a Promise
which resolves with false
, I would expect that the state transition fails. However that's not the case, it continues and calls onEnterState
.
What I noticed is that:
a. If the onBeforeTransition
method is sync and returns false
synchronously, then it behaves as expected and the state transition is canceled.
b. If the onBeforeTransition
method is async and returns a rejected promise, then it also behaves as expected and the state transition is canceled.
Are the docs incorrect maybe? Or is it a bug?
@taoqf/javascript-state-machine is found and imported successfully
but @taoqf/javascript-state-machine/lib/visualize cannot be found
Something looks bad in the minified script which is the entry point of the lib.
I'm using
"react-app-rewired": "^1.5.2",
"react-scripts-ts": "^2.17.0",
webpack "3.8.1"
The problem occures with dev server and production build as well. Do you have any idea what's wrong?
I suspect that setting the main to "dist/state-machine.min.js"
might not be a good idea, the original lib has "lib/state-machine.js"
. Perhaps the double uglification causes a mess. What do you think?
declare class StateMachine {
constructor(options: Partial<StateMachine.Options>);
static factory(options: Partial<StateMachine.Options>): StateMachine.IFSM;
static factory<T>(instance: T, options: Partial<StateMachine.Options>): StateMachine.IFSM | T;
[action: string]: ((...args: any[]) => any);
is: StateMachine.StateMachineIs;
can: StateMachine.StateMachineCan;
cannot: StateMachine.StateMachineCan;
transitions: StateMachine.StateMachineTransitions;
allTransitions: StateMachine.StateMachineTransitions;
allStates: StateMachine.StateMachineStates;
observe: StateMachine.Observe;
// history: string[];
clearHistory(): void;
historyBack(): void;
historyForward(): void;
canHistory(): boolean;
canhistoryForward(): boolean;
}
我扩展了这个状态机类,但是需要用到 state 属性,在 js 中是有的,但是TS中没有定义,可以添加一个吗?
In Typescript 4.1, following line causes an issue
https://github.com/taoqf/javascript-state-machine/blob/master/types/state-machine.d.ts#L5
When calling from code stateMachine[transition]()
, following error is returned by TS
"Not all constituents of type 'string | string[] | ((...args: any[]) => any)' are callable.
Type 'string' has no call signatures."
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.