Hash.subscribe
A browser hash listener system using query string style parameters ( #foo=bar&baz=qux
), based on the subscribe design pattern.
Features:
- Browser Hash initialization
- Subscribe to Hash specific parameters
- Set specific Hash parameter
- Mute / Unmute subscription
CHANGELOG
INSTALL
$ npm install hash.subscribe
USAGE
var Hash = ; // Init browser hashHash; // Set parameters (object)Hash; // Set hash (string)Hash; // Update one key valueHash; // Delete one paramHash; // Subscribe to parameter(s)Hash; // More examples in the test file...
API
init(hash)
Parameter:
hash
- String | Object - default hash to initialize the page with
getHash(keepHash)
Get current hash
Parameter:
keepHash
- Boolean - whether or not to keep the hash character in the return string
Returns: String
getParams
Get current hash parameters
Returns: Object
getParam(key)
Get values of one hash parameter
Parameter:
key
- string - parameter name
Returns: Array
setHash(hash)
Updates current hash
Parameter:
hash
- String | Object - new hash
updateHashKeyValue(key, value)
Updates one hash key
Parameters:
key
- String - hash key to updatevalue
- Array - new value(s) for key
deleteParam(params)
Deletes hash param(s)
Parameter:
params
- String | Array - param(s) name(s) to delete
subscribe([hashParameters], callback)
Subscribe to specific parameters
Parameters:
hashParameters
- Array - Array of parameters names you want to subscribe tocallback
- Function - Callback function called when a parameter has changed
mute()
Mutes subscription to Hash
unmute()
Resume subscription to Hash
destroy()
Destroys current hash value
CONTRIBUTE
Development task
$ git clone git@github.com:raiseandfall/Hash.subscribe.git && cd Hash.subscribe$ npm run dev
Run tests independently
$ npm run test
LICENSE
MIT