![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
👉演示视频
npm install -g 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 3 weekly downloads. As such, afsm popularity was classified as not popular.
We found that afsm demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.