Comparing version 2.0.3 to 2.0.4
24
index.js
@@ -23,3 +23,3 @@ import EventEmitter from 'eventemitter3'; | ||
get() { | ||
let result = []; | ||
let result = new Set(); | ||
let plain = []; | ||
@@ -30,7 +30,4 @@ let forceTo = []; | ||
stateConfig.forEach(({ from, to, action }) => { | ||
allState.add(to); | ||
if (typeof from === 'string') { | ||
allState.add(from); | ||
plain.push({ from, to, action }); | ||
allState.add(action + "ing"); | ||
} | ||
@@ -40,6 +37,4 @@ else { | ||
from.forEach(f => { | ||
allState.add(f); | ||
plain.push({ from: f, to, action }); | ||
}); | ||
allState.add(action + "ing"); | ||
} | ||
@@ -51,12 +46,21 @@ else | ||
plain.forEach(({ from, to, action }) => { | ||
result.push(`${from} --> ${action}ing : ${action}`, `${action}ing --> ${to} : ${action} 🟢`, `${action}ing --> ${from} : ${action} 🔴`); | ||
allState.add(from); | ||
allState.add(to); | ||
allState.add(action + "ing"); | ||
result.add(`${from} --> ${action}ing : ${action}`); | ||
result.add(`${action}ing --> ${to} : ${action} 🟢`); | ||
result.add(`${action}ing --> ${from} : ${action} 🔴`); | ||
}); | ||
forceTo.forEach(({ to, action }) => { | ||
result.push(`${action}ing --> ${to} : ${action} 🟢`); | ||
result.add(`${action}ing --> ${to} : ${action} 🟢`); | ||
allState.forEach(f => { | ||
if (f !== to) | ||
result.push(`${f} --> ${action}ing : ${action}`); | ||
result.add(`${f} --> ${action}ing : ${action}`); | ||
}); | ||
}); | ||
return result; | ||
const parent = Object.getPrototypeOf(target); | ||
if (stateDiagram.has(parent)) { | ||
return [...parent.stateDiagram, ...result]; | ||
} | ||
return [...result]; | ||
} | ||
@@ -63,0 +67,0 @@ }); |
24
index.ts
@@ -21,3 +21,3 @@ import EventEmitter from 'eventemitter3'; | ||
get() { | ||
let result: string[] = []; | ||
let result = new Set<string>(); | ||
let plain: { from: string; to: string; action: string; }[] = []; | ||
@@ -28,14 +28,9 @@ let forceTo: { to: string; action: string; }[] = []; | ||
stateConfig.forEach(({ from, to, action }) => { | ||
allState.add(to); | ||
if (typeof from === 'string') { | ||
allState.add(from); | ||
plain.push({ from, to, action }); | ||
allState.add(action + "ing"); | ||
} else { | ||
if (from.length) { | ||
from.forEach(f => { | ||
allState.add(f); | ||
plain.push({ from: f, to, action }); | ||
}); | ||
allState.add(action + "ing"); | ||
} | ||
@@ -46,12 +41,21 @@ else forceTo.push({ to, action }); | ||
plain.forEach(({ from, to, action }) => { | ||
result.push(`${from} --> ${action}ing : ${action}`, `${action}ing --> ${to} : ${action} 🟢`, `${action}ing --> ${from} : ${action} 🔴`); | ||
allState.add(from); | ||
allState.add(to); | ||
allState.add(action + "ing"); | ||
result.add(`${from} --> ${action}ing : ${action}`); | ||
result.add(`${action}ing --> ${to} : ${action} 🟢`); | ||
result.add(`${action}ing --> ${from} : ${action} 🔴`); | ||
}); | ||
forceTo.forEach(({ to, action }) => { | ||
result.push(`${action}ing --> ${to} : ${action} 🟢`); | ||
result.add(`${action}ing --> ${to} : ${action} 🟢`); | ||
allState.forEach(f => { | ||
if (f !== to) | ||
result.push(`${f} --> ${action}ing : ${action}`); | ||
result.add(`${f} --> ${action}ing : ${action}`); | ||
}); | ||
}); | ||
return result; | ||
const parent = Object.getPrototypeOf(target); | ||
if (stateDiagram.has(parent)) { | ||
return [...parent.stateDiagram, ...result]; | ||
} | ||
return [...result]; | ||
} | ||
@@ -58,0 +62,0 @@ }); |
{ | ||
"name": "afsm", | ||
"version": "2.0.3", | ||
"version": "2.0.4", | ||
"description": "atomic fsm", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -5,2 +5,5 @@ # 智能状态机 | ||
- 原理:通过装饰器,对异步函数进行包装,使得调用异步函数可以自动修改状态,并且自动实现异步调用过程中的中间状态。 | ||
👉[演示视频](https://www.bilibili.com/video/BV1kv4y1T7v4/) | ||
# 安装 | ||
@@ -7,0 +10,0 @@ |
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
3592666
43
15536
81
1