Skip to content

Commit

Permalink
Adds codehighlight to codeblocks
Browse files Browse the repository at this point in the history
  • Loading branch information
anshulguleria committed Feb 4, 2016
1 parent 927e88d commit 7fd54c3
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Smartjax stores your api responses and do not ping the server for the same ajax

**Example**

You display your logged in user's summery in the right top cornor of your site. But to display that in every page you either need to make an ajax call, or have to make a server side processing. But using smartjax, you will get rid of all those processing.
You display your logged in user's summery in the right top cornor of your site. But to display that in every page you either need to make an ajax call, or have to make a server side processing. But using smartjax, you will get rid of all those processing.

Display it by making an ajax call using Smartjax. It will make the first call to get the user info and will store it internally. You can store the information for page level, tab's lifetime level or for forever. You can clear the entire store or the response for a particular one anytime you want.

Expand All @@ -26,32 +26,37 @@ This is very very simple to use the smartjax. Below is a comparison.

**In jQuery:**

```javascript
$.ajax({
url:'http://httpbin.org/post',
type: 'POST',
data:{
a:1,b:2
}
});
```

**In Smartjax:**

```javascript
Smartjax.ajax({
url:'http://httpbin.org/post',
type: 'POST',
data:{
a:1,b:2
}
});
```

Smartjax caches the result in the client side, and response with the same if you make the call again.
Smartjax caches the result in the client side, and response with the same if you make the call again.

## Different level of caching

Using the property *store* you can decide should the response be stored till the page refresh, or till the tab closes or forever.

**Page level**

```javascript
Smartjax.ajax({
url:'http://httpbin.org/post',
type: 'POST',
Expand All @@ -60,11 +65,13 @@ Using the property *store* you can decide should the response be stored till the
},
store:"page"
});
```

This will clear the response once you reload the page or nvigate to another page.

**Tab level**

```javascript
Smartjax.ajax({
url:'http://httpbin.org/post',
type: 'POST',
Expand All @@ -73,11 +80,13 @@ This will clear the response once you reload the page or nvigate to another page
},
store:"tab"
});
```

This will keep the response till the user closes the tab. Even if he refreshes the page or navigate to another, the response will still be with smartjax and will be retured from client side cache of called again. This is also the default store of smartjax.

**Forever**

```javascript
Smartjax.ajax({
url:'http://httpbin.org/post',
type: 'POST',
Expand All @@ -86,13 +95,15 @@ This will keep the response till the user closes the tab. Even if he refreshes t
},
store:"forever"
});
```

You don't wanna remove the response of a particular call? Use *forever* as the value of *store*. However smartjax provide you methods to clean your entire store or a particular call response. So you can clear things explicitly, any time you want.

**do not store**

If *store* property is set to false in the call, the response will not be saved. If you do not want to store by default, you can change the store property in defaults. In the next point you will find how to set defaults.

```javascript
Smartjax.ajax({
url:'http://httpbin.org/post',
type: 'POST',
Expand All @@ -101,6 +112,7 @@ If *store* property is set to false in the call, the response will not be saved.
},
store:false
});
```


## How to control data flow:
Expand All @@ -111,6 +123,7 @@ With some extra parameter in the Smartjax.ajax() call you can control the behavi

If *force* property is true in a call, no matter even if the response is saved, but smartjax will make and fresh call and shore the new result.

```javascript
Smartjax.ajax({
url:'http://httpbin.org/post',
type: 'POST',
Expand All @@ -119,12 +132,14 @@ If *force* property is true in a call, no matter even if the response is saved,
},
force:true
});
Defaulty the value is false.
```
Default the value is false.

**id**

You can provide individual *id* to each call. So that you can individually identify a call. You can clear the saved response of an id.

```javascript
Smartjax.ajax({
url:'http://httpbin.org/post',
type: 'POST',
Expand All @@ -133,11 +148,13 @@ You can provide individual *id* to each call. So that you can individually ident
},
id:"i1"
});
```

**group**

You can group the calls using the *group* parameter. For the time being, the group is useful at the time of cleaning the store.

```javascript
Smartjax.ajax({
url:'http://httpbin.org/post',
type: 'POST',
Expand All @@ -146,38 +163,45 @@ You can group the calls using the *group* parameter. For the time being, the gro
},
group:"group1"
});
```

**cleanStore(param)**

This function is used to clean the store. You can provide list of groups or ids or both to be cleaned.


```javascript
Smartjax.cleanStore({groups:["g1"], ids:["i1"]});
```


**cleanAll()**

This function is parameterless and cleans all the saved records.


```javascript
Smartjax.cleanAll();
```

The function takes an object as a parameter. where you can mention the properties given above. By default the default call method is 'get', but you can change it for all calls. Same in case of force and store.


#Url manipulation
#Url manipulation

Smartjax has started supporting url manipulations. Now you can change your browser url without reloading the page using the folowing.

**changeUrl()**

```javascript
Smartjax.changeUrl({
url:'/my-relative-url',
params:{
query1:'query text',
myQuery:'my own query'
}
});
```

The property 'url' is optional. If you don't provide, it will execute with current url. The second property 'params' is to take a JSON object with query string params and values. If any param is already present in the url it will replace the previous value with the new one you provide.
The property 'url' is optional. If you don't provide, it will execute with current url. The second property 'params' is to take a JSON object with query string params and values. If any param is already present in the url it will replace the previous value with the new one you provide.


## Pipelined features
Expand Down

0 comments on commit 7fd54c3

Please sign in to comment.