redux-geo
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

Redux-geo documentation

No other dependencies needed besides redux! This package will allow you to periodically update your redux store with user gps information.

Setting up your store

const reducers = geoCombineReducers({});
 
export const store: Store<CombinedState<{ geo: GeoStoreState }>, AnyAction> = createStore(reducers, {
    geo: geoInitialState,
});

Example of use

const wait = (time: number) => new Promise(resolve => setTimeout(resolve, time));
store.subscribe(() => {
    // tslint:disable-next-line: no-console
    console.log(store.getState());
});
 
let unsubscribe = geoSubscribe(store, 2000, 2, true, 0.5);
 
if (!unsubscribe) {
    console.error('NO GPS!');
} else {
    (async () => {
        await wait(8000);
        unsubscribe();
        unsubscribe = geoSubscribe(store, 1000, 1, false)!;
        await wait(2000);
        unsubscribe();
    })();
}

Relevant information

This package may cause browsers like Firefox to repeatedly ask for user location, if the user does not give permanent access to geolocation. The package may execute promisified geolocation action after cancelling, if such action has already been scheduled. The package also persists user denial of api until page reload I'm still very much a beginner, so use this with caution.

Update timer

The wait cycle works like this:

  1. Wait for geo api to respond
  2. Wait for set amount of ms
  3. Repeat until cycles run out / unsubscribed / denied

For more information, see the test project right in this repo.

Package Sidebar

Install

npm i redux-geo

Weekly Downloads

0

Version

1.0.2

License

MIT

Unpacked Size

14.7 kB

Total Files

21

Last publish

Collaborators

  • jindra12