npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rx-ajax

v0.1.2

Published

Simple ajax reactive library.

Downloads

91

Readme

NPM version Dependency Status Build Status

Donate

Rx-Ajax

Super simple (but advanced) ajax reactive library. Using RxJS. Supports sending files.

Installation

$ npm install rx-ajax

Usage

import {Http} from 'rx-ajax';

let http = new Http;
let data = {number: 5};
let options = {};

http.request('/users', 'GET', data, options).subscribe((response) => {
	console.log(response.json());
});

Shortcuts

http.get('/api', data, options).subscribe((response) => {});
http.post('/api', data, options).subscribe((response) => {});
http.files('/api', filesList, data, options).subscribe((response) => {});

Options

  • jsonp: name of callback for jsonp requests, when true is given callback name is used. Default is false
  • jsonPrefix: prefix for json requests. Read more here. Default is null
  • mimeType: Default is null
  • headers: List of headers to be send to server. Default is {}
  • files: List of files to be send to server. Default is []

Queue

By default all your requests are called from queue one by one, so there is always just one request running (or zero). Inspiration is from this article http://blog.alexmaccaw.com/queuing-ajax-requests.

You can disable this feature with ImmediateQueue:

import {Http} from 'rx-ajax';
import {ImmediateQueue} from 'rx-ajax/queue';

let http = new Http({
	queue: new ImmediateQueue
});

Events

http.send.subscribe(function(response, request) {
    console.log('In any moment, new http request will be send to server');
});

http.afterSend.subscribe(function(response, request) {
    console.log('I just sent some request to server, but there is still no response');
});

http.success.subscribe(function(response, request) {
    console.log('I have got response from server without any error :-)');
});

http.error.subscribe(function(err, response, request) {
    console.log('Sorry, there was some error with this response');
});

Extensions

Sometimes it will be better to register whole group of events and this group is called extension.

import {AbstractExtension} from 'rx-ajax/extensions';
import {Request, Response} from 'rx-ajax';

class CustomExtension extends AbstractExtension
{

	public send(request: Request): void
	{
		// todo
	}

	public afterSend(request: Request): void
	{
		// todo
	}

	public success(response: Response): void
	{
		// todo
	}

	public error(err: Error): void
	{
		// todo
	}

}

// ...

http.addExtension(new CustomExtension);

Built in extensions

Links

This extension listen for all click events on A tags with ajax class and call them via ajax.

import {Links} from 'rx-ajax/extensions';

http.addExtension(new Links);

Loading

import {Loading} from 'rx-ajax/extensions';

http.addExtension(new Loading);

Offline

This extension tests if your favicon.ico is accessible. You can change test destination by specifying Offline's constructor argument.

import {Offline} from 'rx-ajax/extensions';

http.addExtension(new Offline);

http.connected.subscribe(function() {
    alert("We're online again :-)");
});

http.disconnected.subscribe(function() {
    alert('Lost internet connection');
});

Redirect

If your server sends json data with redirect variable, then you will be redirected to address in this variable.

import {Redirect} from 'rx-ajax/extensions';

http.addExtension(new Redirect);

Snippets

If there is snippets object in response data with html id and content pairs, then this extension will iterate through this object, find element in page with given id and change content of given element into the one from response data.

import {Snippets} from 'rx-ajax/extensions';

http.addExtension(new Snippets);

Known limitations

  • All non ASCII chars (eg. letters with diacritics) in file names are converted to ASCII chars before uploading.