-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhow-to.js
35 lines (22 loc) · 1.25 KB
/
how-to.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//# XTriggerEvent
//javascript customed event for for browser and nodejs. With O dependency. Written by a novice!
//How to use it? Very easy to use. A basic use case:
import XTriggerEvent from "./XTriggerEvent.js";
class Caddy extends XTriggerEvent{addProduct(prod){
prod = prod || {name:"milk xxl nonvo", price:"20", ref:"xxlmilk-00T-234"}
this.registerEvent("addProduct", prod)
}
removeProduct(prod){
prod = prod || {name:"milk xxl nonvo", price:"20", ref:"xxlmilk-00T-234"}
this.registerEvent("removeProduct",prod)
}
}
let mycaddy = new Caddy()
function simp(arg){ console.log("\n1- Turn left to find similar products! If your are not interrested in '"+arg.name+"' .")}
mycaddy.triggerOn("addProduct",(_)=>{ console.log("\n2- Add with success! '", _.name,"'")})
mycaddy.triggerOn("addProduct", (_)=>{ console.log("\n3- Add two more units '"+ _.name +"' to get 60% discount on! Thanx!")})
mycaddy.triggerOn("removeProduct",(_)=>{ console.log("\n4- Are sure , you don't need '"+ _.name +"' !.")})
mycaddy.triggerOn("removeProduct",simp)
mycaddy.addProduct();
mycaddy.removeProduct();
//##end !