Skip to content

Commit

Permalink
skip property
Browse files Browse the repository at this point in the history
  • Loading branch information
m1ga committed Aug 20, 2022
1 parent e81ff2d commit ec098df
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "reste",
"version": "1.6.0",
"version": "1.7.0",
"description": "A JavaScript REST / API helper for Titanium with Alloy Models/Collections support",
"titaniumManifest": {
"guid": "afafe8b0-b93b-771c-a9e5-4e71db81b9ff"
Expand Down
16 changes: 11 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ api.config({

A couple of useful hooks or events can be used within your RESTe global configuration. Those hooks will happen before specific calls are made. They will be executed before any request is sent allowing you to a) change the parameters or b) stop the call happening.

beforePost:
#### beforePost:

This one is quite useful if you need to change the parameters which are going to be used for the request. You might for example -- if you're using Parse Server -- want to strip out certain parameters from models before sending them.

Example:
**Example:**
```javascript
{
...
Expand All @@ -156,11 +156,12 @@ Example:
...
}
```
beforeSend:

These are similar to beforeSend but works for all requests (GET, PUT, DELETE, POST). If you specify both beforePost and beforeLoad then beforePost will go first, then beforeSend.
#### beforeSend:

Example:
These are similar to beforeSend but works for all requests (GET, PUT, DELETE, POST). If you specify both `beforePost` and `beforeLoad` then `beforePost` will go first, then `beforeSend`. Inside `beforeSend` or `beforePost` you can call the `callback()` method with `skip:true` so it will still fire your `success` callback but _without_ making the API call. Use this e.g. to load offline fallback data inside your `success` method:

**Example:**
```javascript
{
...
Expand All @@ -169,6 +170,11 @@ Example:
callback(data);
} else {
alert("No internet connection!");
callback({
skip: true,
error: "no_internet"
});
// will call your success method and pass `error:no_internet` to it
}
},
...
Expand Down
10 changes: 9 additions & 1 deletion reste.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,19 @@ function main() {
if (args.method === 'POST' && typeof beforePost === 'function') {

beforePost(args.params, (e) => {
if (e.skip) {
onLoad(e);
return;
}
args.params = e;
send();
});
} else if (typeof beforeSend === 'function') {
beforeSend(args.params, (e) => {
if (e.skip) {
onLoad(e);
return;
}
args.params = e;
send();
});
Expand Down Expand Up @@ -581,4 +589,4 @@ function main() {
return reste;
}

module.exports = main;
module.exports = main;

0 comments on commit ec098df

Please sign in to comment.