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

emberx-xml-http-request

v0.2.3

Published

Beautiful, transparent uploads and downloads optimized for templating

Downloads

13

Readme

emberx-xml-http-request

npm version Build Status

Easily achieve beautiful, transparent uploads and downloads with a reactive XmlHttpRequest

emberx-xml-http-request is an ember binding to the x-request library

It allows you to declaratively make xml http requests in your templates by injecting an object modelling the request into your templates.

{{x-xml-http-request method="PUT" timeout=12000 url="http://fileupload.com" as |xhr|}}
  name: {{file.name}}<br/>
  bytes uploaded: {{xhr.upload.loaded}} <br/>
  bytes total: {{xhr.upload.total}} <br/>
  percentage complete: {{xhr.upload.percentage}}

  <button {{action (action xhr.send file)}}>Send</button>
  <button {{action (action xhr.abort)}}>Abort</button>

{{/x-xml-http-request}}

Actions

In order to get the XHR to do stuff, you'll need to invoke actions on it. These actions are just JavaScript functions that are attached to the object yielded into the template.

send(data: String | Blob | ArrayBufferView | FormData)

Use this action to initiate the request and start transferring bytes. The optional data parameter will be used as the body of the request. E.g.

{{! send a string}}
<button {{action (action xhr.send "Hello World")}}>Say Hello To Server</button>

{{! send a file}}
<button {{action (action xhr.send file)}}>Send File</button>

{{! etc...}}

See XMLHttpRequest#send() for more about the valid types for data.

abort()

Cancel the current request.

<button {{action (action xhr.abort)}}>Cancel</button>

reset()

Recreate the request entirely and start from scratch. This is useful if you have aborted a request, or it times out, and you want to send it again, but nothing else about the request has changed.

<button {{action (pipe xhr.reset (action xhr.send file))}}>Retry</button>

State

All of the properties of the the xhr param, including readyState, status, response, responseText, etc... are reactive and can be bound to in templates, and can also be used as the input for other computed properties.

{
  readyState: 0,
  requestHeaders: {},
  responseHeaders: {},
  responseType: 'json'
  response: '',
  responseText: '',
  responseXML: '',
  isLoadStarted: false, // alias for download.isLoadStarted
  isLoadEnded: false,   // alias for download.isLoadEnded
  isAborted: false,     // alias for download.isAborted
  isErrored: false,     // alias for download.isErrored
  isTimedOut: false,    // alias for download.isTimedOut
  download: {
    isLoadStarted: false,
    isLoadEnded: false,
    isAborted: false,
    isErrored: false,
    isLengthComputable: false,
    total: 0,
    loaded: 0,
    ratio: 0,
    percentage: 0
  },
  upload: {
    isLoadStarted: false,
    isLoadEnded: false,
    isAborted: false,
    isErrored: false,
    isLengthComputable: false,
    total: 0,
    loaded: 0,
    ratio: 0,
    percentage: 0
  }
}

This is particularly useful in tracking the progress of an upload or a download.

Because xhr radiates all information about its progress, building UIs to track it are a snap.

Installation

ember install emberx-xml-http-request

Code of Conduct

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms, which can be found in the CODE_OF_CONDUCT.md file in this repository.