Socket
Socket
Sign inDemoInstall

mobx-location

Package Overview
Dependencies
7
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    mobx-location

minimal observable wrapper around browser location utilizing popstate event of HTML5 history api


Version published
Weekly downloads
65
increased by6.56%
Maintainers
1
Install size
1.19 MB
Created
Weekly downloads
 

Readme

Source

mobx-location

a browser location as a mobx observable. Minimal wrapper around browser history utilizing popstate event and HTML5 history api. Package history-events is used for monkeypatching.

Prime usage is in your mobx observers. You can directly access the location and your app will rerender itself without the need for react-router or similar solution.

import makeMobxLocation from './mobx-location'
import { autorun, toJS } from 'mobx'

const mobxLocation = makeMobxLocation({ hashHistory: false }) // default
const mobxLocation = makeMobxLocation({ hashHistory: true }) // when you use hash history instead of html5 history APIs

const mobxLocation = makeMobxLocation({ arrayFormat: 'bracket' }) // default
const mobxLocation = makeMobxLocation({ arrayFormat: 'index' }) // will index array params in the url, refer to https://www.npmjs.com/package/query-string#arrayformat

autorun(() => {
  toJS(location) // runs every time browser location changes
})

location has all the standard properties:

hash
host
hostname
href
origin
pathname
port
protocol
search

plus one extra- query. Query is just parsed location.search. Query is always there even if no search params are in your location.

If you modify the query object, it will propagate back to the window location so you don't have to construct the search params yourself when modifying. Keep in mind that any newly added property in query won't be picked up-you must use set from import {set} from 'mobx' to set new props.

Browser support

same as html5 history api-so with that shim even IE9

Keywords

FAQs

Last updated on 15 Oct 2018

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc