flyd-stream-querystring

0.2.1 • Public • Published

flyd-stream-querystring

Flyd module for binding a stream of values to the URL querystring. You may do this with as many streams as you want simultaneously. Also, the values from the URL querystring will pushed to the streams on pageload, if present. This is useful for storing and tracking UI state in the URL to be restored on pageload (like for searching, filtering, or tracking what page they are on).

Signature

String -> Stream a -> Stream a

This module exports a single function that takes a String (a query parameter key name) and an existing stream and binds the values from that stream into the URL querystring under the given key.

Usage

const stream = require('flyd').stream
const queryString = require('flyd-stream-querystring')
 
location.search // -> ""
 
const finn = stream(), jake = stream()
 
queryString('finn', finn)
queryString('jake', jake)
 
finn('human')
location.search // -> "?finn=human"
jake('dog')
location.search // -> "?finn=human&jake=dog"
finn('human-boy') 
location.search // -> "?finn=human-boy&jake=dog"
 
// Pushing empty string or null to a querystring stream makes the value blank
finn(null)
location.search // -> "?finn=&jake=dog"
 
// Pushing undefined to a querystring stream removes it from the url
finn(undefined)
location.search // -> "?jake=dog"

Readme

Keywords

none

Package Sidebar

Install

npm i flyd-stream-querystring

Weekly Downloads

1

Version

0.2.1

License

ISC

Last publish

Collaborators

  • jayrbolton
  • the_swerve