Skip to content

Commit 7e5d9fa

Browse files
committed
refactor debugger for instantiation support
1 parent a279252 commit 7e5d9fa

5 files changed

Lines changed: 18 additions & 36 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ and this project tries its best to use [Semantic Versioning](http://semver.org/)
1414
- ScrollReveal removes generated styles after reveals complete when `options.reset` is `false`. [#292](https://github.com/jlmakes/scrollreveal/issues/292)
1515
- New `clean()` method removes specific generated styles and event listeners. [#227](https://github.com/jlmakes/scrollreveal/issues/227)
1616
- New `destroy()` method removes all generated styles and event listeners. [#227](https://github.com/jlmakes/scrollreveal/issues/227)
17-
- New `debug` instance property toggles error messages in console. [#351](https://github.com/jlmakes/scrollreveal/issues/351)
17+
- New `debug` static property toggles error messages in console. [#351](https://github.com/jlmakes/scrollreveal/issues/351)
1818
- Instance methods now accept native arrays of HTML elements.
1919

2020
### Changed

src/instance/constructor.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,6 @@ export default function ScrollReveal (options = {}) {
2828
return new ScrollReveal(options)
2929
}
3030

31-
Object.defineProperty(this, 'debug', {
32-
get: () => _debug || false,
33-
set: value => {
34-
if (typeof value === 'boolean') _debug = value
35-
},
36-
})
37-
3831
if (!ScrollReveal.isSupported()) {
3932
logger.call(this, 'Instantiation aborted.', 'This browser is not supported.')
4033
return noop
@@ -100,10 +93,6 @@ export default function ScrollReveal (options = {}) {
10093
return _instance ? _instance : _instance = this
10194
}
10295

103-
<<<<<<< Updated upstream
104-
ScrollReveal.isSupported = () => transformSupported() && transitionSupported()
105-
106-
=======
10796
/**
10897
* Static members are available immediately during instantiation,
10998
* so debugging and browser support details are handled here.
@@ -123,7 +112,6 @@ ScrollReveal.isSupported = () => transformSupported() && transitionSupported()
123112
* The primary API is comprised
124113
* of these instance methods:
125114
*/
126-
>>>>>>> Stashed changes
127115
ScrollReveal.prototype.clean = clean
128116
ScrollReveal.prototype.destroy = destroy
129117
ScrollReveal.prototype.reveal = reveal

src/utils/core.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export function getScrolled (container) {
117117

118118

119119
export function logger (message, ...details) {
120-
if (this.debug && console) {
120+
if (this.constructor.debug && console) {
121121
let report = `ScrollReveal: ${message}`
122122
details.forEach(detail => report += `\n - ${detail}`)
123123
console.log(report) // eslint-disable-line no-console

test/instance/constructor.spec.js

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,19 @@ describe('ScrollReveal', () => {
7575
ScrollReveal({ duration: 5000 })
7676
expect(ScrollReveal().defaults.duration).to.equal(5000)
7777
})
78+
79+
it('should have a static `debug` property', () => {
80+
expect(ScrollReveal.debug).to.exist
81+
expect(ScrollReveal.debug).to.be.a('boolean')
82+
})
83+
84+
it('should only accept boolean values for static `debug` property', () => {
85+
ScrollReveal.debug = null
86+
expect(ScrollReveal.debug).to.exist
87+
expect(ScrollReveal.debug).to.be.a('boolean')
88+
ScrollReveal.debug = true
89+
expect(ScrollReveal.debug).to.be.true
90+
})
7891
})
7992

8093
describe('Instance', () => {
@@ -101,24 +114,6 @@ describe('ScrollReveal', () => {
101114
expect(sr.sync).to.be.a('function')
102115
})
103116

104-
it('should have a `debug` property', () => {
105-
expect(sr.debug).to.exist
106-
expect(sr.debug).to.be.a('boolean')
107-
})
108-
109-
it('should have a `debug` property', () => {
110-
expect(sr.debug).to.exist
111-
expect(sr.debug).to.be.a('boolean')
112-
})
113-
114-
it('should only accept boolean values for `debug` property', () => {
115-
sr.debug = null
116-
expect(sr.debug).to.exist
117-
expect(sr.debug).to.be.a('boolean')
118-
sr.debug = true
119-
expect(sr.debug).to.be.true
120-
})
121-
122117
it('should have a `delegate` property', () => {
123118
expect(sr.delegate).to.exist
124119
expect(sr.delegate).to.be.a('function')

test/utils/core.spec.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,10 @@ describe('Core Utilities', () => {
9393

9494
describe('logger()', () => {
9595

96+
const mock = { constructor: { debug: true } }
97+
9698
let spy
9799
let stub
98-
let mock = { debug: true }
99100

100101
before('stub console log', () => {
101102
spy = sinon.spy()
@@ -117,8 +118,6 @@ describe('Core Utilities', () => {
117118
expect(spy).to.have.been.calledWith('ScrollReveal: message\n - detail one\n - detail two')
118119
})
119120

120-
after('restore console log', () => {
121-
stub.restore()
122-
})
121+
after('restore console log', () => stub.restore())
123122
})
124123
})

0 commit comments

Comments
 (0)