param-store
v1.2.0
Published
param store for react
Downloads
7
Readme
param-store
param-store manage the url. What's special about it is it treats url as independent params which can be set and get.
API
ParamStore
import ParamStore from 'param-store'
// path is a special param in the sense that it is the path in the url
// instead of in the query part.
// Otherwise it is the same as other query params.
// SETTER
// `set` MERGE the new params with the previous params in the url
ParamStore.set({path: 'login'}) // change path
ParamStore.set({userId: 'f38adfn'}) // change userId
ParamStore.set({path: 'user', userId: 'f38adfn'}) // change path and userId
// `setAll` RESETS the whole url and ignore the previous url
Paramstore.setAll({path: 'login'}) // overwrite current params
// Options:
// options apply to set and setAll as the second argument
// replaceState: replace instead of push to history stack
// e.g.
ParamStore.set({ path: 'login' }, {replaceState: true})
// GETTER
ParamStore.get('path') // get 'path' from params
ParamStore.getAll() // get whole params object
// LISTENNER
const listener = ParamStore.listen('path', 'tab', function(report){
const {changedParams, currentParams, previousParams} = report
})
ParamStore.unlisten(listener)
connect
import {connect} from 'param-store'
connect(Login, 'path', 'tab’) // path and tab will be passed as props
Link
// Link use `setAll` under the hood
import {Link} from 'param-store'
<Link type='button' params={{path: 'about'}}>this is an anchor tag</Link>
DEVELOPMENT
test
npm run browser
build: NOTE: before buiding, remove node_modules/history