@@ -18,9 +18,14 @@ import $ from 'tealight'
18
18
19
19
import { version } from '../../package.json'
20
20
21
- let _config
22
- let _debug
23
- let _instance
21
+ let boundDelegate
22
+ let boundDestroy
23
+ let boundReveal
24
+ let boundClean
25
+ let boundSync
26
+ let config
27
+ let debug
28
+ let instance
24
29
25
30
export default function ScrollReveal ( options = { } ) {
26
31
const invokedWithoutNew =
@@ -41,37 +46,30 @@ export default function ScrollReveal(options = {}) {
41
46
* assigning the contents to the private variable `_config`.
42
47
*/
43
48
let buffer
44
- {
45
- try {
46
- buffer = _config
47
- ? deepAssign ( { } , _config , options )
48
- : deepAssign ( { } , defaults , options )
49
- } catch ( e ) {
50
- logger . call (
51
- this ,
52
- 'Instantiation failed.' ,
53
- 'Invalid configuration.' ,
54
- e . message
55
- )
56
- return noop
57
- }
49
+ try {
50
+ buffer = config
51
+ ? deepAssign ( { } , config , options )
52
+ : deepAssign ( { } , defaults , options )
53
+ } catch ( e ) {
54
+ logger . call ( this , 'Instantiation failed.' , 'Invalid configuration.' , e . message )
55
+ return noop
56
+ }
58
57
59
- try {
60
- const container = $ ( buffer . container ) [ 0 ]
61
- if ( ! container ) {
62
- throw new Error ( 'Invalid container.' )
63
- }
64
- if ( ( ! buffer . mobile && isMobile ( ) ) || ( ! buffer . desktop && ! isMobile ( ) ) ) {
65
- throw new Error ( 'This device is disabled.' )
66
- }
67
- } catch ( e ) {
68
- logger . call ( this , 'Instantiation failed.' , e . message )
69
- return noop
58
+ try {
59
+ const container = $ ( buffer . container ) [ 0 ]
60
+ if ( ! container ) {
61
+ throw new Error ( 'Invalid container.' )
70
62
}
71
-
72
- _config = buffer
63
+ if ( ( ! buffer . mobile && isMobile ( ) ) || ( ! buffer . desktop && ! isMobile ( ) ) ) {
64
+ throw new Error ( 'This device is disabled.' )
65
+ }
66
+ } catch ( e ) {
67
+ logger . call ( this , 'Instantiation failed.' , e . message )
68
+ return noop
73
69
}
74
70
71
+ config = buffer
72
+
75
73
/**
76
74
* Modify the DOM to reflect successful instantiation.
77
75
*/
@@ -93,17 +91,23 @@ export default function ScrollReveal(options = {}) {
93
91
94
92
this . pristine = true
95
93
96
- Object . defineProperty ( this , 'delegate' , { get : ( ) => delegate . bind ( this ) } )
97
- Object . defineProperty ( this , 'destroy' , { get : ( ) => destroy . bind ( this ) } )
98
- Object . defineProperty ( this , 'reveal' , { get : ( ) => reveal . bind ( this ) } )
99
- Object . defineProperty ( this , 'clean' , { get : ( ) => clean . bind ( this ) } )
100
- Object . defineProperty ( this , 'sync' , { get : ( ) => sync . bind ( this ) } )
94
+ boundDelegate = boundDelegate || delegate . bind ( this )
95
+ boundDestroy = boundDestroy || destroy . bind ( this )
96
+ boundReveal = boundReveal || reveal . bind ( this )
97
+ boundClean = boundClean || clean . bind ( this )
98
+ boundSync = boundSync || sync . bind ( this )
99
+
100
+ Object . defineProperty ( this , 'delegate' , { get : ( ) => boundDelegate } )
101
+ Object . defineProperty ( this , 'destroy' , { get : ( ) => boundDestroy } )
102
+ Object . defineProperty ( this , 'reveal' , { get : ( ) => boundReveal } )
103
+ Object . defineProperty ( this , 'clean' , { get : ( ) => boundClean } )
104
+ Object . defineProperty ( this , 'sync' , { get : ( ) => boundSync } )
101
105
102
- Object . defineProperty ( this , 'defaults' , { get : ( ) => _config } )
106
+ Object . defineProperty ( this , 'defaults' , { get : ( ) => config } )
103
107
Object . defineProperty ( this , 'version' , { get : ( ) => version } )
104
108
Object . defineProperty ( this , 'noop' , { get : ( ) => false } )
105
109
106
- return _instance ? _instance : ( _instance = this )
110
+ return instance ? instance : ( instance = this )
107
111
}
108
112
109
113
/**
@@ -113,6 +117,6 @@ export default function ScrollReveal(options = {}) {
113
117
ScrollReveal . isSupported = ( ) => transformSupported ( ) && transitionSupported ( )
114
118
115
119
Object . defineProperty ( ScrollReveal , 'debug' , {
116
- get : ( ) => _debug || false ,
117
- set : value => ( _debug = typeof value === 'boolean' ? value : _debug )
120
+ get : ( ) => debug || false ,
121
+ set : value => ( debug = typeof value === 'boolean' ? value : debug )
118
122
} )
0 commit comments