File tree Expand file tree Collapse file tree 2 files changed +12
-13
lines changed Expand file tree Collapse file tree 2 files changed +12
-13
lines changed Original file line number Diff line number Diff line change @@ -72,9 +72,15 @@ describe('EStyleSheet API', function () {
72
72
} ) ;
73
73
} ) ;
74
74
75
- it ( 'should throw error on second `build` call' , function ( ) {
76
- api . build ( ) ;
77
- expect ( ( ) => api . build ( ) ) . toThrowError ( 'No need to call `EStyleSheet.build()` more than once' ) ;
75
+ it ( 'should work correctly with several `build()` calls' , function ( ) {
76
+ const res1 = api . create ( { $b : '$a' } ) ;
77
+ api . build ( { a : 1 } ) ;
78
+ const res2 = api . create ( { $b : '$a' } ) ;
79
+ expect ( res1 ) . toEqual ( { $b : 1 } ) ;
80
+ expect ( res2 ) . toEqual ( { $b : 1 } ) ;
81
+ api . build ( { a : 2 } ) ;
82
+ expect ( res1 ) . toEqual ( { $b : 2 } ) ;
83
+ expect ( res2 ) . toEqual ( { $b : 2 } ) ;
78
84
} ) ;
79
85
80
86
it ( 'should calculate value' , function ( ) {
Original file line number Diff line number Diff line change @@ -34,9 +34,8 @@ export default class {
34
34
let sheet = new Sheet ( obj ) ;
35
35
if ( this . builded ) {
36
36
sheet . calc ( this . globalVars ) ;
37
- } else {
38
- this . sheets . push ( sheet ) ;
39
37
}
38
+ this . sheets . push ( sheet ) ;
40
39
return sheet . getResult ( ) ;
41
40
}
42
41
@@ -45,11 +44,7 @@ export default class {
45
44
* @param {Object } [gVars]
46
45
*/
47
46
build ( gVars ) {
48
- if ( this . builded ) {
49
- throw new Error ( 'No need to call `EStyleSheet.build()` more than once' ) ;
50
- } else {
51
- this . builded = true ;
52
- }
47
+ this . builded = true ;
53
48
this . _calcVars ( gVars ) ;
54
49
this . _calcSheets ( ) ;
55
50
this . _callListeners ( BUILD_EVENT ) ;
@@ -95,13 +90,11 @@ export default class {
95
90
96
91
_calcSheets ( ) {
97
92
this . sheets . forEach ( sheet => sheet . calc ( this . globalVars ) ) ;
98
- this . sheets . length = 0 ;
99
93
}
100
94
101
95
_callListeners ( event ) {
102
- if ( this . listeners [ event ] ) {
96
+ if ( Array . isArray ( this . listeners [ event ] ) ) {
103
97
this . listeners [ event ] . forEach ( listener => listener ( ) ) ;
104
- delete this . listeners [ event ] ;
105
98
}
106
99
}
107
100
}
You can’t perform that action at this time.
0 commit comments