redux-location

0.0.17 • Public • Published

redux-location NPM version Discord

Redux service to request and store multiple user geolocation

alt tag

alt tag

FEATURES

  • Service architecture (redux-manager powered)
  • Journaling (redux-journal powered)
  • Persist state (PouchDB powered)
  • Dynamic service configuration (state.config):
    • docsMax = 2 - maximum docs in state.docs
    • docsMaxOverRemove: true - remove old locations over docsMax

INSTALL

Stable

npm i -S redux-location

Dev

npm i -S lokhmakov/redux-location

EXAMPLES

REACT

npm run react

client.js

require('redux-journal').enable()

import injectTapEventPlugin from 'react-tap-event-plugin'

injectTapEventPlugin()

import PouchDB              from 'pouchdb'

import { manager }          from 'redux-manager'
import { locationLocal }    from 'redux-location'
import { locationPersist }  from 'redux-location'

const service1 = 'location'
const service2 = 'location2'
const service3 = 'location3'

locationLocal({ serviceName: service1 })
locationPersist({ db: PouchDB('redux-location'), serviceList: [service1] })

locationLocal({ serviceName: service2 })
locationLocal({ serviceName: service3 })

manager.enableLogger(require('redux-logger')())
const store = manager.getStore()

import React                from 'react'
import ReactDOM             from 'react-dom'
import { Provider }         from 'react-redux'
import { connect }          from 'react-redux'

import MuiThemeProvider     from 'material-ui/styles/MuiThemeProvider'
import getMuiTheme          from 'material-ui/styles/getMuiTheme'

import { LocationBadge }    from 'redux-location'
import { LocationButton }   from 'redux-location'
import { LocationObserver } from 'redux-location'

const LocationBadge1    = connect(state => ({ location: state[service1] }))(LocationBadge)
const LocationBadge2    = connect(state => ({ location: state[service2] }))(LocationBadge)
const LocationBadge3    = connect(state => ({ location: state[service3] }))(LocationBadge)
const LocationButton3   = connect(state => ({ location: state[service3] }))(LocationButton)
const LocationObserver3 = connect(state => ({ location: state[service3] }))(LocationObserver)

const muiTheme = getMuiTheme({ palette: { accent1Color: require('material-ui/styles/colors').deepOrange500 }})

const render = () => ReactDOM.render(
  <Provider store={ store }>
    <MuiThemeProvider muiTheme={ muiTheme }>
      <div>
        <LocationBadge1 serviceName={ service1 } />
        <LocationBadge2   serviceName={ service2 } />
        <LocationBadge3   serviceName={ service3 } />
        <LocationButton3  serviceName={ service3 } />
        <LocationObserver3 />
      </div>
    </MuiThemeProvider>
  </Provider>,
  document.getElementById('root')
)

render()

NODE-API

npm run node

require('redux-journal').enable()

import { write, error }   from 'redux-journal'
import { manager }        from 'redux-manager'
import { locationLocal }  from 'redux-location'

const api = locationLocal()

manager.enableLogger(require('redux-node-logger')())
manager.getStore()

api.locate().then((position) => {
  write(position)
}).catch((e) => {
  error(e)
})

PERSIST

npm run persist

alt tag

require('redux-journal').enable()

import PouchDB              from 'pouchdb'
import { manager }          from 'redux-manager'
import { locationActions }  from 'redux-location'
import { locationLocal }    from 'redux-location'
import { locationPersist }  from 'redux-location'

const db = PouchDB('data/location', { db: require('memdown') })

locationLocal()
locationPersist({ db })

manager.enableLogger(require('redux-node-logger')())
manager.getStore()

manager.dispatch(locationActions.insert({ lat: 'latitude', lng: 'longitude' }), 'location')

Package Sidebar

Install

npm i redux-location

Weekly Downloads

1

Version

0.0.17

License

MIT

Last publish

Collaborators

  • lokhmakov