Created
April 11, 2014 13:15
-
-
Save JonMidhir/10467885 to your computer and use it in GitHub Desktop.
Aborting a Backbone Collection fetch request
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Collection.fetch() returns a Xhr that you can store in a variable. | |
# The request can be aborted if the Xhr readystate is 1,2 or 3. | |
# | |
# Note: If readystate == 3 the request has already been sent and the | |
# server will continue to process it, the response will be ignored. | |
class App.Routers.Posts extends Backbone.Router | |
routes: | |
'': 'index' | |
':id': 'show' | |
initialize: -> | |
@collection = new App.Collections.Posts() | |
@view = new App.Views.PostsIndex(collection: @collection, el: '#posts') | |
index: -> | |
# Money | |
@fetchXhr.abort() if @fetchXhr?.readyState in [1..3] | |
@fetchXhr = @collection.fetch | |
reset: true | |
show: (id) -> | |
# ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment