Skip to content

Commit

Permalink
new dependency versions, update readme, rename api -> driver, update …
Browse files Browse the repository at this point in the history
…demo
  • Loading branch information
Zlobin committed May 27, 2016
1 parent e081390 commit 05bf206
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 36 deletions.
19 changes: 9 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,9 @@ var cache = function(next) {
console.log('Data from a cache.');
// Do not send request to the server.
// Return cached response.
return new Promise(function(resolse, reject) {
resolse({
response: response,
headers: []
});
return Promise.resolse({
response: response,
headers: []
});
} else {
console.log('Send request to the server.');
Expand Down Expand Up @@ -163,11 +161,11 @@ Or if you want to allow to use only GET requests:
```js
var onlyGet = function(next) {
return this.request.method === 'GET' ?
next() : new Promise(function(resolse, reject) {
reject({
response: 'Only "GET" methods is available.',
headers: []
});
next() :
Promise.reject({
status: 0,
response: 'Available only "GET" requests',
headers: []
});
};
Expand Down Expand Up @@ -229,3 +227,4 @@ You can grab minified versions of es-ajax from /dist path after running `webpack
2. Add more tests
3. Singleton request
4. Add custom parameters to the demo
5. Add polyfill for IE(10, 11) for Promises.
13 changes: 7 additions & 6 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ <h3 class="panel-title">Response</h3>
<script>
(function(document, ajax) {
var byId = document.getElementById.bind(document);

var send = byId('send');
var abort = byId('abort');
var abortAll = byId('abort-all');
Expand All @@ -125,6 +126,7 @@ <h3 class="panel-title">Response</h3>
var progressBar = byId('progressbar');
var applyMiddleware = byId('apply-middleware');
var clearMiddleware = byId('clear-middleware');

var activeRequest = null;
// For checking json object as parameters
// with nested objects and arrays.
Expand All @@ -146,6 +148,7 @@ <h3 class="panel-title">Response</h3>
'baz'
]
};

var responseOut = function(response) {
try {
response.response = JSON.parse(response.response);
Expand Down Expand Up @@ -197,12 +200,10 @@ <h3 class="panel-title">Response</h3>

return requests.method === 'GET' ?
next() :
new Promise(function(resolve, reject) {
reject({
status: 0,
response: 'Only "GET" requests',
headers: []
});
Promise.reject({
status: 0,
response: 'Available only "GET" requests',
headers: []
});
};

Expand Down
28 changes: 14 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "es-ajax",
"description": "Ajax (fetch or xhr2) with promises - an useful JavaScript library for convenient work with ajax requests in a browser.",
"version": "1.1.3",
"version": "1.1.4",
"main": "src/index.js",
"files": [
"src",
Expand Down Expand Up @@ -38,35 +38,35 @@
],
"license": "MIT",
"dependencies": {
"es-middleware": "^1.1.0",
"es-middleware": "^1.1.1",
"object-hash": "^1.1.2",
"qs": "^6.1.0"
"qs": "^6.2.0"
},
"devDependencies": {
"babel-cli": "^6.8.0",
"babel-core": "^6.8.0",
"babel-cli": "^6.9.0",
"babel-core": "^6.9.0",
"babel-loader": "^6.2.4",
"babel-plugin-transform-export-extensions": "^6.8.0",
"babel-plugin-transform-object-rest-spread": "^6.8.0",
"babel-polyfill": "^6.8.0",
"babel-preset-es2015": "^6.6.0",
"babel-polyfill": "^6.9.0",
"babel-preset-es2015": "^6.9.0",
"babel-preset-stage-2": "^6.5.0",
"eslint": "^2.10.1",
"eslint": "^2.10.2",
"eslint-config-airbnb": "^9.0.1",
"eslint-loader": "^1.3.0",
"eslint-plugin-import": "^1.8.0",
"eslint-plugin-jsx-a11y": "^1.2.0",
"eslint-plugin-import": "^1.8.1",
"eslint-plugin-jsx-a11y": "^1.2.2",
"eslint-plugin-react": "^5.1.1",
"expect": "^1.20.1",
"karma": "^0.13.22",
"karma-mocha": "^0.2.2",
"karma-mocha": "^1.0.1",
"karma-phantomjs-launcher": "^1.0.0",
"karma-sinon": "^1.0.5",
"karma-webpack": "^1.7.0",
"mocha": "^2.4.5",
"mocha": "^2.5.3",
"phantomjs-prebuilt": "^2.1.7",
"sinon": "^1.17.3",
"webpack": "^1.13.0"
"sinon": "^1.17.4",
"webpack": "^1.13.1"
},
"engines": {
"node": ">=4"
Expand Down
2 changes: 1 addition & 1 deletion src/api/fetch.js → src/driver/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import internal from './utils/internal';
import { methods } from './utils/methods';
import { is } from '../utils/is';

export default class FetchAPI extends XhrAbstract {
export default class FetchDriver extends XhrAbstract {
constructor(url, request = {}, headers = {}) {
super();

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/api/xhr.js → src/driver/xhr.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { methods } from './utils/methods';
import asObject from './utils/as-object';
import { is } from '../utils/is';

export default class XhrAPI extends XhrAbstract {
export default class XhrDriver extends XhrAbstract {
constructor(url, request = {}, headers = {}) {
super();

Expand Down
8 changes: 4 additions & 4 deletions src/utils/factory.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import FetchAPI from '../api/fetch.js';
import XhrAPI from '../api/xhr.js';
import FetchDriver from '../driver/fetch.js';
import XhrDriver from '../driver/xhr.js';

export default function factory(type, url, request, headers) {
return type === 'fetch' ?
new FetchAPI(url, request, headers) :
new XhrAPI(url, request, headers);
new FetchDriver(url, request, headers) :
new XhrDriver(url, request, headers);
}

0 comments on commit 05bf206

Please sign in to comment.