Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@sheknows/frisbee

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sheknows/frisbee

Data collection transport library

  • 0.2.0
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Frisbee

Frisbee is a small cross-browser (IE10+) data collection library. It incorporates a queue and a HTTP client. You define endpoint to hit and keep adding data to Frisbee. Frisbee takes care of the rest.

Getting started

Load Frisbee

<script src="/frisbee.js"></script>

Instantiate Frisbee

var frisbee = new window.Frisbee({
  namespace: 'ns',
  url: 'http://foo/bar'
})

Now add some data to it.

frisbee.add(1)
frisbee.add(2)
frisbee.add(3)
frisbee.add(4)
frisbee.add(5)
frisbee.add(6)

Frisbee fills the queue with data until maxItems is reached (5 by default). At that point, Frisbee removes first 5 items from the queue and POSTs them to the options.url. In this example, Frisbee will POST http://foo/bar with the following request payload:

{
  "payload": [1, 2, 3, 4, 5],
  "meta": {
    "namespace": "ns",
    "id": "<instance-specific-uuid>"
  } 
}

6th item (now 1st) will wait until 4 more are added until another POST. Structure of the request payload can be changed using getRequestData function. More info below.

Let's add 1 more item.

frisbee.add(1)

Now we have two items waiting. But let's assume that in your app lifecycle at some point(s) you must ensure that the entire queue is drained and POSTed. We can use

frisbee.sendAll()

This will POST http://foo/bar

{
  "payload": [6, 1],
  "meta": {
    "namespace": "ns",
    "id": "<instance-specific-uuid>" 
  } 
}

Another use-case for sendAll method would be setting a timer to periodically POST data regardless of the maxItems criteria.

Options

{
  // Number of items in the queue to reach when the request is made
  // Default: 5
  maxItems: Number, 

  // HTTP verb to use for requests
  // Default: 'POST'
  method: String,

  // URL to hit
  // Default: undefined
  url: String,

  // HTTP headers to include
  // Default: { 'Content-type': 'application/json; charset=utf-8' }
  headers: Object,

  // Namespace
  // Default: undefined
  namespace: [String, Number, Object],

  // Transform request payload before the request.
  // Runs before every request. This method needs to return a truthy value for request to happen.
  // See example in example/scroll.js
  // Default: 
  //   function (data, meta) {
  //     return JSON.stringify({
  //       payload: data,
  //       meta: meta
  //     })
  //   }
  getRequestData: Function
}

Gotchas

Use getRequestData wisely

Mutating data

Because you have access to data array (of currently emptied queue data), you could append some extra data through this modifier that Frisbee does not know about. Keep in mind that mutating data will have no effect on subsequent calls to this function since every request works with a fresh set of (different) data.

Mutating meta

Mutated meta object however will carry on for all subsequent getRequestData calls. Use that your (dis)advantage.

Must return truthy value

Because request will fire only if this method returns a truthy value, it opens up interesting possibilities. For example, if you want to bundle multiple namespaces into one request, you could create a main frisbee instance to talk to API and bundle several different namespaces while other Frisbee (namespace-specific) instances would be used as queues and never talk to the API, just to the main API Frisbee instance.

FAQs

Package last updated on 01 Jun 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc