Skip to content

Instantly share code, notes, and snippets.

@allanphilipbarku
Forked from bitfishxyz/final.js
Created February 12, 2020 02:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save allanphilipbarku/2e178ede7d6ebce1d55e4e0bc8785185 to your computer and use it in GitHub Desktop.
Save allanphilipbarku/2e178ede7d6ebce1d55e4e0bc8785185 to your computer and use it in GitHub Desktop.
const actions = ()=>{
const functionA = ()=>{/*do sth*/}
const functionB = ()=>{/*do sth*/}
const functionC = ()=>{/*send log*/}
return new Map([
[/^guest_[1-4]$/,functionA],
[/^guest_5$/,functionB],
[/^guest_.*$/,functionC],
//...
])
}
const onButtonClick = (identity,status)=>{
let action = [...actions()].filter(([key,value])=>(key.test(`${identity}_${status}`)))
action.forEach(([key,value])=>value.call(this))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment