Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
👉演示视频
npm install afsm
import { FSM, ChangeState } from 'afsm'
class MyFSM extends FSM {
@ChangeState(FSM.INIT,'state1')
async gotoState1() {
}
@ChangeState('state1','state2')
async gotoState2() {
}
}
const obj = new MyFSM()
obj.gotoState2()//will throw error
obj.gotoState1().then(()=>{//will change to state1
return obj.gotoState2()//then change to state2
})
其他对象如果希望得知状态机的变化,可以通过监听事件实现。
每一种状态变更时,都会发出事件,如果是中间过渡状态则会自动加ing。
const obj = new MyFSM()
obj.on('gotoState2ing',(oldState) => {
console.log(obj,'is going to state2')
})
obj.on('state2',(oldState) => {
console.log(obj,'is state2 now')
})
此外为了方便监听所有事件,还会同时发出changeStated事件。异步调用的成功与失败都会导致状态变更,可以通过下面的监听来判断。
const obj = new MyFSM()
obj.on(FSM.STATECHANGED,(newState:State, oldState:State) => {
})
其中State的定义参考下面的源码中的定义
export type State = string | MiddleState;
// 中间过渡状态
export class MiddleState {
constructor(public oldState: State, public newState: string, public action: string) {
}
toString() {
return `${this.action}ing`;
}
}
afsm浏览器扩展可以在开发人员工具的标签页中生成一个可视化页面,供实时观察代码运行的情况。
1.将仓库 clone 下来后,打开浏览器扩展管理,点击加载解压缩的扩展,选择仓库中的 devtools/dist 目录。 2.打开一个页面,并打开控制台,选择智能状态机标签,即可看到扩展页面。 3.当项目中使用了AFSM后,会自动向扩展页面发送信息,扩展页面可以看到项目中的状态机图以及状态机的变更记录。
FAQs
automatic finite state machine
The npm package afsm receives a total of 509 weekly downloads. As such, afsm popularity was classified as not popular.
We found that afsm demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.