Skip to content

Commit

Permalink
Only refresh once during an enableAll call, imakewebthings#454
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
imakewebthings committed Jun 22, 2016
1 parent cc044d9 commit 1d90d5b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"gulp-tap": "^0.1.1",
"gulp-uglify": "^0.3.1",
"merge-stream": "^0.1.1",
"testem": "^0.6.24"
"testem": "0.6.24"
},
"license": "MIT"
}
6 changes: 5 additions & 1 deletion src/waypoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@
/* Public */
/* http://imakewebthings.com/waypoints/api/enable-all */
Waypoint.enableAll = function() {
Waypoint.invokeAll('enable')
Waypoint.Context.refreshAll()
for (var waypointKey in allWaypoints) {
allWaypoints[waypointKey].enabled = true
}
return this
}

/* Public */
Expand Down
21 changes: 15 additions & 6 deletions test/waypoint-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -527,20 +527,29 @@ window.jQuery.each(Waypoint.adapters, function(i, adapter) {
})

describe('Waypoint.enableAll()', function() {
it('calls enable on all waypoints', function() {
var secondWaypoint = new Waypoint({
var secondWaypoint

beforeEach(function() {
secondWaypoint = new Waypoint({
element: $('#same1')[0],
handler: function() {}
})
waypoint = new Waypoint({
element: $('#same1')[0],
handler: function() {}
})
spyOn(secondWaypoint, 'enable').andCallThrough()
spyOn(waypoint, 'enable').andCallThrough()
Waypoint.disableAll()
spyOn(Waypoint.Context, 'refreshAll').andCallThrough()
Waypoint.enableAll()
expect(secondWaypoint.enable).toHaveBeenCalled()
expect(waypoint.enable).toHaveBeenCalled()
})

it('sets enabled on all waypoints', function() {
expect(secondWaypoint.enabled).toBeTruthy()
expect(waypoint.enabled).toBeTruthy()
})

it('refreshes all contexts', function() {
expect(Waypoint.Context.refreshAll).toHaveBeenCalled()
})
})
})
Expand Down

0 comments on commit 1d90d5b

Please sign in to comment.