Skip to content

Commit

Permalink
renamed to as-service
Browse files Browse the repository at this point in the history
  • Loading branch information
ahadrt committed Jul 21, 2018
1 parent 86fb9f1 commit d24b0b1
Show file tree
Hide file tree
Showing 26 changed files with 2,724 additions and 1,534 deletions.
10 changes: 7 additions & 3 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
{
"presets":[
["env", {
["@babel/preset-env", {
"targets": {
"node": "6.10"
"node": "6.10",
"browsers": ["last 2 versions"]
}



}]
],
"plugins": ["transform-class-properties"]
"plugins": ["@babel/plugin-proposal-class-properties"]
}
4 changes: 4 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
src
.git
.npmignore

42 changes: 23 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
# BtService
# AsService
---
## a parametric, observable and injectable service based on rxjs as a javascript library using axios for connect to http server (XHR) and localforge for cache in indexedDB

### install:

```js
npm i @barteh/btservice --save
npm i @barteh/as-service --save
```

### usage:
#### import library
```js
import {BtService,BtServer} from "@barteh/btservice"
import {AsService,Server} from "@barteh/as-service"
```

#### 1- primitive type (number | string | Array) as service
```js
var srv1=new BtService(5); // number as service
var srv1=new AsService(5); // number as service
srv1.Observable()
.subscribe(a=>console.log("ser1 data via observable is:",a));

srv1.load().then(a=>console.log("ser1 data via promis:",a));
```


#### 2- pure object as service
#### 2- pure object as service
```js
var srv2=new BtService({x:9}); // object as service
var srv2=new AsService({x:9}); // object as service

srv2.Observable()
.subscribe(a=>console.log("ser2 data via observable is:",a));
Expand All @@ -36,7 +36,7 @@ srv2.load().then(a=>console.log("ser2 data via promis:",a));

#### 3- function as service (parametric observable)
```js
var srv3=new BtService(param=>param*3); // function as service
var srv3=new AsService(param=>param*3); // function as service
srv3.Observable(2) //parametric observe
.subscribe(a=>console.log("ser3 data via observable is:",a));

Expand All @@ -46,23 +46,25 @@ srv3.load(2).then(a=>console.log("ser3 data via promis:",a));

#### 4- Promise as service
```js
var ser4=new BtService(param=>new Promise((res,rej)=>res(`im promise with parameter: ${param}`)));
var ser4=new AsService(param=>new Promise((res,rej)=>res(`im promise with parameter: ${param}`)));

ser4.Observable("myparam")
.subscribe(a=>console.log("srv4: ",a));

ser4.load("myparam");
```
#### 5- XHR as parameter
using built in advanced methods name [ BtServer ] wraps axios and localforge for cache data
can use Btserver as imput of Btservice
#### 5- XHR as Service
>using built in advanced methods name [ Server ] wraps axios for retrive data from http server and localforge for cache data.
following sample uses class [ Server ] as input of AsService. you can use your own xhr library insteed of this.


if http://myserver/contacts/getcontact.ctrl http REST service is exist

```js

var server=(x,y)=>new BtServer.controller("contacts","getcontact",{name:x,lname:y});
var controller1=(x,y)=>Server BtServer.controller("contacts","getcontact",{name:x,lname:y});

var srv5=new BtService(server);
var srv5=new AsService(controller1);

srv5.Observable("Ahad","Rafat")
.subscribe(a=>console.log("srv5:",a));
Expand All @@ -79,17 +81,19 @@ srv5.Observable("Ahad","Rafat")
```

### Test:
`npm run test`
`npm test`

## usig Both for web and browsers

## usig Es5
for using this service in ES5 projet need to build and get it from dist folder
### Build
### Build
`npm run build`


### use in ES5
```js
var {BtService} =require("@barteh/btservice/dist/bt-service");
var {AsService} =require("@barteh/as-service")

var t=new BtService(8);
var t=new AsService(8);

t.Observable()
.subscribe(a=>console.log(a))
Expand Down
208 changes: 0 additions & 208 deletions dist/bt-server.js

This file was deleted.

Loading

0 comments on commit d24b0b1

Please sign in to comment.