This repository has been archived by the owner on Apr 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinter.js
85 lines (70 loc) · 1.51 KB
/
inter.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
module.exports = function CrInterfice(testes, log){
var is_test = false;
this.test = function(new_testes, new_log){
if(new_testes){
if(typeof(new_testes[0]) == "function"
&& typeof(new_testes[1]) == "function"){
testes = new_testes;
is_test = true;
}else{
console.error(new Error("Test is not function!"));
is_test = false;
}
}
if(new_log){
if(typeof new_log == "function") log = new_log; else log = null;
}
}
if(testes) this.test(testes, log);
var InputOne = null;
var OutputOne = null;
this.connect = function(outputFunc){
if(OutputOne){
if(is_test){
var begFunc = outputFunc;
outputFunc = function(val){
testes[0](val);
if(log) log(" One: ", val);
begFunc(val);
}
}
return TwoConnect(outputFunc);
}
else{
if(is_test){
var begFunc = outputFunc;
outputFunc = function(val){
testes[1](val);
if(log) log(" Two: ", val);
begFunc(val);
}
}
return OneConnect(outputFunc);
}
};
function OneConnect(outputFunc){
OutputOne = outputFunc;
InputOne = CrHoarder();
return function(val){
InputOne(val);
}
}
function TwoConnect(outputFunc){
if(InputOne.take) InputOne.take(outputFunc);
InputOne = outputFunc;
return OutputOne;
}
}
function CrHoarder(){
var hoarder = [];
var push = function(val){
hoarder.push(val);
};
push.take = function(func){
if(typeof func != "function") return hoarder;
hoarder.forEach(function(val){
func(val);
});
}
return push;
}