1-
2- var test = require ( 'tape' ) ;
1+ var test = require ( 'tape' )
32// require('tabe').createStream( test );
4- var dop = require ( './.proxy' ) . create ( ) ;
5-
6-
7-
8- var object = dop . register ( { } ) ;
3+ var dop = require ( './.proxy' ) . create ( )
94
5+ var object = dop . register ( { } )
106
117test ( 'Collect as default' , function ( t ) {
12- var collector = dop . collect ( ) ;
13- dop . set ( object , 'array' , [ ] ) ;
14- t . equal ( collector . mutations . length , 1 ) ;
15- t . equal ( collector . mutations [ 0 ] . object . array , object . array ) ;
16- collector . destroy ( ) ;
17- t . end ( ) ;
18- } ) ;
19-
8+ var collector = dop . collect ( )
9+ dop . set ( object , 'array' , [ ] )
10+ t . equal ( collector . mutations . length , 1 )
11+ t . equal ( collector . mutations [ 0 ] . object . array , object . array )
12+ collector . destroy ( )
13+ t . end ( )
14+ } )
2015
2116test ( 'Multiple collectors order' , function ( t ) {
22- var collector1 = dop . collect ( ) ;
23- var collector2 = dop . collect ( ) ;
24- object . array . push ( Math . random ( ) ) ;
25- t . equal ( collector1 . mutations . length , 1 ) ;
26- t . equal ( collector2 . mutations . length , 0 ) ;
27- collector1 . destroy ( ) ;
28- collector2 . destroy ( ) ;
29- t . end ( ) ;
30- } ) ;
31-
32-
33- test ( 'Using collectFirst' , function ( t ) {
34- var collector1 = dop . collect ( ) ;
35- var collector2 = dop . collect ( function ( ) { return 0 } ) ;
36- object . array . push ( Math . random ( ) ) ;
37- var collector3 = dop . collect ( ) ;
38- object . array . push ( Math . random ( ) ) ;
39- var collector4 = dop . collect ( function ( ) { return 0 } ) ;
40- object . array . push ( Math . random ( ) ) ;
41- t . equal ( collector1 . mutations . length , 0 ) ;
42- t . equal ( collector2 . mutations . length , 2 ) ;
43- t . equal ( collector3 . mutations . length , 0 ) ;
44- t . equal ( collector4 . mutations . length , 1 ) ;
45- collector1 . destroy ( ) ;
46- collector2 . destroy ( ) ;
47- collector3 . destroy ( ) ;
48- collector4 . destroy ( ) ;
49- t . end ( ) ;
50- } ) ;
51-
52-
17+ var collector1 = dop . collect ( )
18+ var collector2 = dop . collect ( )
19+ object . array . push ( Math . random ( ) )
20+ t . equal ( collector1 . mutations . length , 0 )
21+ t . equal ( collector2 . mutations . length , 1 )
22+ collector1 . destroy ( )
23+ collector2 . destroy ( )
24+ t . end ( )
25+ } )
26+
27+ test ( 'Using index_function' , function ( t ) {
28+ var collector1 = dop . collect ( )
29+ var collector2 = dop . collect ( function ( ) {
30+ return 0
31+ } )
32+ object . array . push ( Math . random ( ) )
33+ var collector3 = dop . collect ( )
34+ object . array . push ( Math . random ( ) )
35+ var collector4 = dop . collect ( function ( ) {
36+ return 0
37+ } )
38+ object . array . push ( Math . random ( ) )
39+ t . equal ( collector1 . mutations . length , 0 )
40+ t . equal ( collector2 . mutations . length , 1 )
41+ t . equal ( collector3 . mutations . length , 1 )
42+ t . equal ( collector4 . mutations . length , 1 )
43+ collector1 . destroy ( )
44+ collector2 . destroy ( )
45+ collector3 . destroy ( )
46+ collector4 . destroy ( )
47+ t . end ( )
48+ } )
49+
50+ test ( 'Using index_function 2' , function ( t ) {
51+ var collector2 = dop . collect ( function ( ) {
52+ return 0
53+ } )
54+ object . array . push ( Math . random ( ) )
55+ var collector3 = dop . collect ( )
56+ object . array . push ( Math . random ( ) )
57+ var collector4 = dop . collect ( function ( collectors ) {
58+ return collectors . length
59+ } )
60+ object . array . push ( Math . random ( ) )
61+ t . equal ( collector2 . mutations . length , 1 )
62+ t . equal ( collector3 . mutations . length , 2 )
63+ t . equal ( collector4 . mutations . length , 0 )
64+ collector2 . destroy ( )
65+ collector3 . destroy ( )
66+ collector4 . destroy ( )
67+ t . end ( )
68+ } )
5369
5470test ( 'Active and inactive collectores' , function ( t ) {
55- var collector1 = dop . collect ( ) ;
56- object . array . push ( Math . random ( ) ) ;
57- var collector2 = dop . collect ( ) ;
58- object . array . push ( Math . random ( ) ) ;
59- collector1 . active = false ;
60- object . array . push ( Math . random ( ) ) ;
61- collector1 . active = true ;
62- object . array . push ( Math . random ( ) ) ;
63- t . equal ( collector1 . mutations . length , 3 ) ;
64- t . equal ( collector2 . mutations . length , 1 ) ;
65- collector1 . destroy ( ) ;
66- collector2 . destroy ( ) ;
67- t . end ( ) ;
68- } ) ;
69-
70-
71+ var collector1 = dop . collect ( )
72+ object . array . push ( Math . random ( ) )
73+ var collector2 = dop . collect ( )
74+ object . array . push ( Math . random ( ) )
75+ collector1 . active = false
76+ object . array . push ( Math . random ( ) )
77+ collector1 . active = true
78+ object . array . push ( Math . random ( ) )
79+ t . equal ( collector1 . mutations . length , 1 )
80+ t . equal ( collector2 . mutations . length , 3 )
81+ collector1 . destroy ( )
82+ collector2 . destroy ( )
83+ t . end ( )
84+ } )
7185
7286test ( 'Destroying' , function ( t ) {
73- var collector1 = dop . collect ( ) ;
74- object . array . push ( Math . random ( ) ) ;
75- var collector2 = dop . collect ( ) ;
76- object . array . push ( Math . random ( ) ) ;
77- collector1 . destroy ( ) ;
78- object . array . push ( Math . random ( ) ) ;
79- t . equal ( collector1 . mutations . length , 2 ) ;
80- t . equal ( collector2 . mutations . length , 1 ) ;
81- collector1 . destroy ( ) ;
82- collector2 . destroy ( ) ;
83- t . end ( ) ;
84- } ) ;
85-
87+ var collector1 = dop . collect ( )
88+ object . array . push ( Math . random ( ) )
89+ var collector2 = dop . collect ( )
90+ object . array . push ( Math . random ( ) )
91+ collector1 . destroy ( )
92+ object . array . push ( Math . random ( ) )
93+ t . equal ( collector1 . mutations . length , 1 )
94+ t . equal ( collector2 . mutations . length , 2 )
95+ collector1 . destroy ( )
96+ collector2 . destroy ( )
97+ t . end ( )
98+ } )
8699
87100test ( 'Filtering' , function ( t ) {
88- var totalArray = object . array . length ;
89- var collector1 = dop . collect ( ) ;
90- collector1 . filter = function ( mutation ) {
91- return ( mutation . object . length === totalArray + 1 ) ;
92- } ;
93- object . array . push ( Math . random ( ) ) ;
94- var collector2 = dop . collect ( ) ;
95- object . array . push ( Math . random ( ) ) ;
96- t . equal ( collector1 . mutations . length , 1 ) ;
97- t . equal ( collector2 . mutations . length , 1 ) ;
98- object . array . push ( Math . random ( ) ) ;
99- t . equal ( collector1 . mutations . length , 1 ) ;
100- t . equal ( collector2 . mutations . length , 2 ) ;
101+ var totalArray = object . array . length
102+ var collector1 = dop . collect ( )
103+ collector1 . filter = function ( mutation ) {
104+ return mutation . object . length === totalArray + 1
105+ }
106+ object . array . push ( Math . random ( ) )
107+ var collector2 = dop . collect ( )
108+ object . array . push ( Math . random ( ) )
109+ t . equal ( collector1 . mutations . length , 1 )
110+ t . equal ( collector2 . mutations . length , 1 )
111+ object . array . push ( Math . random ( ) )
112+ t . equal ( collector1 . mutations . length , 1 )
113+ t . equal ( collector2 . mutations . length , 2 )
101114 delete collector1 . filter
102- object . array . push ( Math . random ( ) ) ;
103- t . equal ( collector1 . mutations . length , 2 ) ;
104- t . equal ( collector2 . mutations . length , 2 ) ;
105- collector1 . destroy ( ) ;
106- collector2 . destroy ( ) ;
107- t . end ( ) ;
108- } ) ;
109-
110-
115+ object . array . push ( Math . random ( ) )
116+ t . equal ( collector1 . mutations . length , 1 )
117+ t . equal ( collector2 . mutations . length , 3 )
118+ collector1 . destroy ( )
119+ collector2 . destroy ( )
120+ t . end ( )
121+ } )
111122
112123test ( 'Emit' , function ( t ) {
113- var collector = dop . collect ( ) ;
114- object . array . push ( Math . random ( ) ) ;
115- t . equal ( collector . mutations . length , 1 ) ;
116- collector . emitWithoutDestroy ( ) ;
117- t . equal ( collector . mutations . length , 0 ) ;
118- object . array . push ( Math . random ( ) ) ;
119- t . equal ( collector . mutations . length , 1 ) ;
120- collector . emit ( ) ;
121- object . array . push ( Math . random ( ) ) ;
122- t . equal ( collector . mutations . length , 0 ) ;
123- t . end ( ) ;
124- } ) ;
125-
126-
127-
124+ var collector = dop . collect ( )
125+ object . array . push ( Math . random ( ) )
126+ t . equal ( collector . mutations . length , 1 )
127+ collector . emitWithoutDestroy ( )
128+ t . equal ( collector . mutations . length , 0 )
129+ object . array . push ( Math . random ( ) )
130+ t . equal ( collector . mutations . length , 1 )
131+ collector . emit ( )
132+ object . array . push ( Math . random ( ) )
133+ t . equal ( collector . mutations . length , 0 )
134+ t . end ( )
135+ } )
128136
129137test ( 'Testing shadow option on set' , function ( t ) {
130- var collector = dop . collect ( ) ;
131- dop . set ( object , 'noshadow' , [ 2 , 3 , 4 ] )
132- dop . set ( object , 'shadow' , [ 2 , 3 , 4 ] , { shadow :true } )
133- t . equal ( collector . mutations . length , 1 ) ;
134- t . deepEqual ( object . noshadow , object . shadow ) ;
135- collector . destroy ( ) ;
136- t . end ( ) ;
137- } ) ;
138+ var collector = dop . collect ( )
139+ dop . set ( object , 'noshadow' , [ 2 , 3 , 4 ] )
140+ dop . set ( object , 'shadow' , [ 2 , 3 , 4 ] , { shadow : true } )
141+ t . equal ( collector . mutations . length , 1 )
142+ t . deepEqual ( object . noshadow , object . shadow )
143+ collector . destroy ( )
144+ t . end ( )
145+ } )
0 commit comments