Skip to content

Commit 1d90d5b

Browse files
Only refresh once during an enableAll call, imakewebthings#454
Previously, enableAll would invoke enable on each Waypoint, but enable calls refresh on the context. This meant n-refreshes where n is the number of active Waypoints.
1 parent cc044d9 commit 1d90d5b

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"gulp-tap": "^0.1.1",
2929
"gulp-uglify": "^0.3.1",
3030
"merge-stream": "^0.1.1",
31-
"testem": "^0.6.24"
31+
"testem": "0.6.24"
3232
},
3333
"license": "MIT"
3434
}

src/waypoint.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,11 @@
115115
/* Public */
116116
/* http://imakewebthings.com/waypoints/api/enable-all */
117117
Waypoint.enableAll = function() {
118-
Waypoint.invokeAll('enable')
118+
Waypoint.Context.refreshAll()
119+
for (var waypointKey in allWaypoints) {
120+
allWaypoints[waypointKey].enabled = true
121+
}
122+
return this
119123
}
120124

121125
/* Public */

test/waypoint-spec.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -527,20 +527,29 @@ window.jQuery.each(Waypoint.adapters, function(i, adapter) {
527527
})
528528

529529
describe('Waypoint.enableAll()', function() {
530-
it('calls enable on all waypoints', function() {
531-
var secondWaypoint = new Waypoint({
530+
var secondWaypoint
531+
532+
beforeEach(function() {
533+
secondWaypoint = new Waypoint({
532534
element: $('#same1')[0],
533535
handler: function() {}
534536
})
535537
waypoint = new Waypoint({
536538
element: $('#same1')[0],
537539
handler: function() {}
538540
})
539-
spyOn(secondWaypoint, 'enable').andCallThrough()
540-
spyOn(waypoint, 'enable').andCallThrough()
541+
Waypoint.disableAll()
542+
spyOn(Waypoint.Context, 'refreshAll').andCallThrough()
541543
Waypoint.enableAll()
542-
expect(secondWaypoint.enable).toHaveBeenCalled()
543-
expect(waypoint.enable).toHaveBeenCalled()
544+
})
545+
546+
it('sets enabled on all waypoints', function() {
547+
expect(secondWaypoint.enabled).toBeTruthy()
548+
expect(waypoint.enabled).toBeTruthy()
549+
})
550+
551+
it('refreshes all contexts', function() {
552+
expect(Waypoint.Context.refreshAll).toHaveBeenCalled()
544553
})
545554
})
546555
})

0 commit comments

Comments
 (0)