Gathering detailed insights and metrics for vue-easy-state-machine
Gathering detailed insights and metrics for vue-easy-state-machine
Gathering detailed insights and metrics for vue-easy-state-machine
Gathering detailed insights and metrics for vue-easy-state-machine
npm install vue-easy-state-machine
33
Supply Chain
83.1
Quality
69.9
Maintenance
50
Vulnerability
95.3
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
7 Commits
2 Watching
21 Branches
1 Contributors
Updated on 06 Oct 2019
Vue (79.38%)
JavaScript (20.62%)
Cumulative downloads
Total Downloads
Last day
-87.5%
1
Compared to previous day
Last week
144.4%
22
Compared to previous week
Last month
1,500%
32
Compared to previous month
Last year
-1.3%
158
Compared to previous year
1
1
Light state machine packaged as a vue component
1$ npm install vue-easy-state-machine
This packages provides a <easy-state-machine>
component managing a small state machine for UI management
Declare as Vue plugin:
1import VueEasyStateMachine from "vue-easy-state-machine"; 2Vue.use(VueEasyStateMachine);
In your component <script>
section, declare your state table with states & associated behavior:
1export default { 2 data() { 3 return { 4 states: { 5 askEmail: { 6 entry: true, 7 success: "askPassword", 8 failure: "askEmail" 9 }, 10 askPassword: { 11 success: "login", 12 failure: "askEmail" 13 }, 14 login: { 15 success: this.initSession, 16 failure: "askEmail" 17 }, 18 19 //... 20 21 stateXXX: { 22 success: "stateYYY", 23 failure: "stateZZZ" 24 } 25 26 //... 27 } 28 }; 29 }, 30 methods: { 31 initSession() { 32 //... 33 } 34 } 35};
In your component <template>
section, wrap the state machine around components related to each state:
states
prop.#default
variable, in current
array; Only the active state is set to true
, all other are set to false
.easy-state-machine
component exposes success()
and failure()
methods to trigger evolution; You can use restart()
to ... restart.1<easy-state-machine :states="states" #default="state"> 2 <div v-if="state.current.askEmail"> 3 <input type="email" placeholder="Email" /> 4 <button type="button" @click="state.success">Next</button> 5 </div> 6 <div v-if="state.current.askPassword"> 7 <input type="password" placeholder="Password" /> 8 <button type="button" @click="state.success">Next</button> 9 <button type="button" @click="state.failure">Previous</button> 10 </div> 11 <div v-if="state.current.login"> 12 <strong>You are logged</strong> 13 <button type="button" @click="state.success">Init Session</button> 14 <button type="button" @click="state.failure">Restart</button> 15 </div> 16</easy-state-machine>
And that's it !
Each state can handle following items:
1{ 2 "entry": true, 3 "onEnter" : () => {}, 4 "success": "stateXXX", 5 "failure": "stateYYY", 6 "onLeave" : () => {}, 7}
entry
Boolean
false
true
entry per state table. If multiple entries, only the first one is taken.success
String
or Function
undefined
failure
String
or Function
success
entryonEnter
Function
undefined
onLeave
Function
undefined
You can manage complex branching with success
and failure
functions:
1{ 2 "success": () => { return this.myBooleanValue ? 'stateXXX' : 'stateYYY' }, 3 "failure": this.myBranchingFunction, 4}
Where myBranchingFunction
is defined in methods
block:
1methods: {} 2 myBranchingFunction() { 3 if ( /** my test **/ ) 4 return 'stateXXX'; 5 else 6 return 'stateYYY'; 7 } 8}
stateChange
onLeave
and before onEnter
are calledYou can use with <transition>
for a beautiful effect:
1<easy-state-machine :states="states" #default="state"> 2 <transition 3 name="transition-login" 4 enter-active-class="animated fadeIn" 5 leave-active-class="animated fadeOut" 6 mode="out-in" 7 > 8 <div v-if="state.current.askEmail" key="askEmail"> 9 ... 10 </div> 11 <div v-if="state.current.askPassword" key="askPassword"> 12 ... 13 </div> 14 <div v-if="state.current.login" key="login"> 15 ... 16 </div> 17 </transition> 18</easy-state-machine>
Sample application provided in sample
direcory for testing purpose:
1$ npm run sample
Add then open ./sample/index.html in your browser
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/7 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
131 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More