Giter Site home page Giter Site logo

mohammadnouraein / btservice Goto Github PK

View Code? Open in Web Editor NEW

This project forked from barteh/as-service

0.0 1.0 0.0 96 KB

observable data service based on rxjs using axios for conunicate with server via http (XHR).

License: MIT License

JavaScript 100.00%

btservice's Introduction

BtService


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:

npm i barteh/btservice --save

usage:

import library

import {BtService,BtServer} from "@barteh/btservice"

1- primitive type (number | string | Array) as service

var srv1=new BtService(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

var srv2=new BtService({x:9}); // number as service

srv2.Observable()
.subscribe(a=>console.log("ser2 data via observable is:",a));

srv2.load().then(a=>console.log("ser2 data via promis:",a));

3- function as service (parametric observable)

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

//passing (Number) 2  as parameter
srv3.load(2).then(a=>console.log("ser3 data via promis:",a));

4- Promise as service

var ser4=new BtService(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 if http://myserver/contacts/getcontact.ctrl http REST service is exist

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

var srv5=new BtService(server);

srv5.Observable("Ahad","Rafat")
.subscribe(a=>console.log("srv5:",a));

output:



> ser1 data via observable is: 5
> ser2 data via observable is: { x: 9 }
> ser3 data via observable is: 6
> ser1 data via promis: 5
> ser2 data via promis: { x: 9 }
> ser3 data via promis: 6
> srv4:  im promise with parameter: myparam

Test:

npm run test

usig Es5

for using this service in ES5 projet need to build and get it from dist folder

Build

npm run build

var BtService=require("barteh/btservice/dist");

License: MIT

btservice's People

Contributors

ahadrt avatar

Watchers

Mohammad Nouraien avatar

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.