Giter Club home page Giter Club logo

backbone-http-interceptor's Introduction

backbone-http-interceptor

it is a general purpose ajax interceptor for backbone and backbone.marionette framework or any other framework which is build on top of backbone.js.
Using this project you can intercept every ajax request which is fired using backbone models/collections fetch/save method.
During interceptions we given you some default options as below to show/hide spinner/toaster. By modifying the cource code you can also add your custom headers to your request/response.

See example for more information.

Installation

simply include this plugin after everything is loaded except your files

<script src="https://code.jquery.com/jquery-3.1.1.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.3.3/backbone.js"></script>
<script src="http://rawgit.com/nikhil-001mehta/backbone-http-interceptor/master/release/backbone.httpInterceptor.min.js"></script>

Usage

var backboneInterceptor = new Backbone.HttpInterceptor
			backboneInterceptor.start(options object);

available options are

options = {
			spinnerSelector: 'unique selector for showing/hiding the spinner during ajax request is in progress',
			spinnerTextSelector: 'unique selector to show text in spinner i.e. saving/loading/processing etc',
			defaultSpinnerText: 'Texr to show in spinner when nothing is paased in options to backbone.fetch/backbone.save'
			spinnerDisplayStyle: 'block/flex/inline etc'
			toasterSelector: 'unique selector for showing/hiding the spinner after ajax request is processed',
			toasterTextSelector: 'unique selector to show text in toaster',
			defaultToasterText: 'Texr to show in toaster when nothing is paased in options to backbone.fetch/backbone.save'
			toasterDisplayStyle: 'block/flex/inline etc'
			toasterSuccessClass: 'class to apply to toasterSelector when ajax request is succeeds',
			toasterErrorClass: 'class to apply to toasterSelector when ajax request is fails',
		 };

after installation simply call fetch/save method you can see spinner/toaster as per your options

var todoModel = new Backbone.Model({
	url: "http://jsonplaceholder.typicode.com/posts",
});
todoModel.fetch();

You can also supress spinner and toaster for some specific fetch/save calls as shown below

var todoModel = new Backbone.Model({
	url: "http://jsonplaceholder.typicode.com/posts"
});
todoModel.fetch({
	doNotshowSpinner: true,
	doNotshowToaster: true
});

you can abort all pending requests using

backboneInterceptor.abortAllPendingRequests();

you can tell interceptor not to abort the request during abortAllPendingRequests() process

var todoModel = new Backbone.Model({
	url: "http://jsonplaceholder.typicode.com/posts"
});
todoModel.fetch({
	doNotAbort: true
});
todoModel.fetch();
backboneInterceptor.abortAllPendingRequests();

this will abort only second request

backbone-http-interceptor's People

Contributors

technikhil314 avatar

Watchers

 avatar  avatar

Forkers

chowdaryrahul

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.