Socket
Socket
Sign inDemoInstall

redux-first-routing

Package Overview
Dependencies
12
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.3 to 0.1.4

74

lib/actions.js

@@ -1,33 +0,55 @@

import { PUSH, REPLACE, GO, GO_BACK, GO_FORWARD, LOCATION_CHANGE } from './constants';
'use strict';
export const push = href => ({
type: PUSH,
payload: href
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.locationChange = exports.goForward = exports.goBack = exports.go = exports.replace = exports.push = undefined;
export const replace = href => ({
type: REPLACE,
payload: href
});
var _constants = require('./constants');
export const go = index => ({
type: GO,
payload: index
});
var push = exports.push = function push(href) {
return {
type: _constants.PUSH,
payload: href
};
};
export const goBack = () => ({
type: GO_BACK
});
var replace = exports.replace = function replace(href) {
return {
type: _constants.REPLACE,
payload: href
};
};
export const goForward = () => ({
type: GO_FORWARD
});
var go = exports.go = function go(index) {
return {
type: _constants.GO,
payload: index
};
};
export const locationChange = ({ pathname, search, hash }) => ({
type: LOCATION_CHANGE,
payload: {
pathname,
search,
hash
}
});
var goBack = exports.goBack = function goBack() {
return {
type: _constants.GO_BACK
};
};
var goForward = exports.goForward = function goForward() {
return {
type: _constants.GO_FORWARD
};
};
var locationChange = exports.locationChange = function locationChange(_ref) {
var pathname = _ref.pathname,
search = _ref.search,
hash = _ref.hash;
return {
type: _constants.LOCATION_CHANGE,
payload: {
pathname: pathname,
search: search,
hash: hash
}
};
};

@@ -1,6 +0,11 @@

export const PUSH = 'ROUTER/PUSH';
export const REPLACE = 'ROUTER/REPLACE';
export const GO = 'ROUTER/GO';
export const GO_BACK = 'ROUTER/GO_BACK';
export const GO_FORWARD = 'ROUTER/GO_FORWARD';
export const LOCATION_CHANGE = 'ROUTER/LOCATION_CHANGE';
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var PUSH = exports.PUSH = 'ROUTER/PUSH';
var REPLACE = exports.REPLACE = 'ROUTER/REPLACE';
var GO = exports.GO = 'ROUTER/GO';
var GO_BACK = exports.GO_BACK = 'ROUTER/GO_BACK';
var GO_FORWARD = exports.GO_FORWARD = 'ROUTER/GO_FORWARD';
var LOCATION_CHANGE = exports.LOCATION_CHANGE = 'ROUTER/LOCATION_CHANGE';

@@ -1,3 +0,14 @@

import createBrowserHistory from 'history/createBrowserHistory';
'use strict';
export { createBrowserHistory };
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createBrowserHistory = undefined;
var _createBrowserHistory = require('history/createBrowserHistory');
var _createBrowserHistory2 = _interopRequireDefault(_createBrowserHistory);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.createBrowserHistory = _createBrowserHistory2.default;

@@ -1,9 +0,119 @@

// History API
export { createBrowserHistory } from './history';
export { startListener } from './listener';
'use strict';
// Redux API
export { PUSH, REPLACE, GO, GO_BACK, GO_FORWARD, LOCATION_CHANGE } from './constants';
export { push, replace, go, goBack, goForward, locationChange } from './actions';
export { routerMiddleware } from './middleware';
export { routerReducer } from './reducer';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _history = require('./history');
Object.defineProperty(exports, 'createBrowserHistory', {
enumerable: true,
get: function get() {
return _history.createBrowserHistory;
}
});
var _listener = require('./listener');
Object.defineProperty(exports, 'startListener', {
enumerable: true,
get: function get() {
return _listener.startListener;
}
});
var _constants = require('./constants');
Object.defineProperty(exports, 'PUSH', {
enumerable: true,
get: function get() {
return _constants.PUSH;
}
});
Object.defineProperty(exports, 'REPLACE', {
enumerable: true,
get: function get() {
return _constants.REPLACE;
}
});
Object.defineProperty(exports, 'GO', {
enumerable: true,
get: function get() {
return _constants.GO;
}
});
Object.defineProperty(exports, 'GO_BACK', {
enumerable: true,
get: function get() {
return _constants.GO_BACK;
}
});
Object.defineProperty(exports, 'GO_FORWARD', {
enumerable: true,
get: function get() {
return _constants.GO_FORWARD;
}
});
Object.defineProperty(exports, 'LOCATION_CHANGE', {
enumerable: true,
get: function get() {
return _constants.LOCATION_CHANGE;
}
});
var _actions = require('./actions');
Object.defineProperty(exports, 'push', {
enumerable: true,
get: function get() {
return _actions.push;
}
});
Object.defineProperty(exports, 'replace', {
enumerable: true,
get: function get() {
return _actions.replace;
}
});
Object.defineProperty(exports, 'go', {
enumerable: true,
get: function get() {
return _actions.go;
}
});
Object.defineProperty(exports, 'goBack', {
enumerable: true,
get: function get() {
return _actions.goBack;
}
});
Object.defineProperty(exports, 'goForward', {
enumerable: true,
get: function get() {
return _actions.goForward;
}
});
Object.defineProperty(exports, 'locationChange', {
enumerable: true,
get: function get() {
return _actions.locationChange;
}
});
var _middleware = require('./middleware');
Object.defineProperty(exports, 'routerMiddleware', {
enumerable: true,
get: function get() {
return _middleware.routerMiddleware;
}
});
var _reducer = require('./reducer');
Object.defineProperty(exports, 'routerReducer', {
enumerable: true,
get: function get() {
return _reducer.routerReducer;
}
});

@@ -1,5 +0,12 @@

import { locationChange } from './actions';
'use strict';
export function startListener(history, store) {
store.dispatch(locationChange({
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.startListener = startListener;
var _actions = require('./actions');
function startListener(history, store) {
store.dispatch((0, _actions.locationChange)({
pathname: history.location.pathname,

@@ -10,4 +17,4 @@ search: history.location.search,

history.listen(location => {
store.dispatch(locationChange({
history.listen(function (location) {
store.dispatch((0, _actions.locationChange)({
pathname: location.pathname,

@@ -14,0 +21,0 @@ search: location.search,

@@ -1,23 +0,36 @@

import { PUSH, REPLACE, GO, GO_BACK, GO_FORWARD } from './constants';
'use strict';
export const routerMiddleware = history => () => next => action => {
switch (action.type) {
case PUSH:
history.push(action.payload);
break;
case REPLACE:
history.replace(action.payload);
break;
case GO:
history.go(action.payload);
break;
case GO_BACK:
history.goBack();
break;
case GO_FORWARD:
history.goForward();
break;
default:
return next(action);
}
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.routerMiddleware = undefined;
var _constants = require('./constants');
var routerMiddleware = exports.routerMiddleware = function routerMiddleware(history) {
return function () {
return function (next) {
return function (action) {
switch (action.type) {
case _constants.PUSH:
history.push(action.payload);
break;
case _constants.REPLACE:
history.replace(action.payload);
break;
case _constants.GO:
history.go(action.payload);
break;
case _constants.GO_BACK:
history.goBack();
break;
case _constants.GO_FORWARD:
history.goForward();
break;
default:
return next(action);
}
};
};
};
};

@@ -1,5 +0,13 @@

import { parse } from 'query-string';
import { LOCATION_CHANGE } from './constants';
'use strict';
const getInitialState = {
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.routerReducer = undefined;
var _queryString = require('query-string');
var _constants = require('./constants');
var getInitialState = {
pathname: '/',

@@ -11,9 +19,12 @@ search: '',

export const routerReducer = (state = getInitialState, action) => {
var routerReducer = exports.routerReducer = function routerReducer() {
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getInitialState;
var action = arguments[1];
switch (action.type) {
case LOCATION_CHANGE:
case _constants.LOCATION_CHANGE:
return {
pathname: action.payload.pathname,
search: action.payload.search,
queries: parse(action.payload.search),
queries: (0, _queryString.parse)(action.payload.search),
hash: action.payload.hash

@@ -20,0 +31,0 @@ };

{
"name": "redux-first-routing",
"version": "0.1.3",
"version": "0.1.4",
"description": "Redux-first routing",

@@ -67,5 +67,5 @@ "main": "lib/index.js",

"build:umd:min": "cross-env BABEL_ENV=es NODE_ENV=production rollup -c -i src/index.js -o dist/redux-first-routing.min.js",
"test": "mocha --compilers js:babel-core/register test/**/*.spec.js",
"test": "cross-env BABEL_ENV=commonjs mocha --compilers js:babel-core/register test/**/*.spec.js",
"prepublish": "npm run lint && npm run test && npm run clean && npm run build"
}
}

@@ -1,2 +0,2 @@

# Redux-First Routing
# Redux-First Routing [![npm version](https://img.shields.io/npm/v/redux-first-routing.svg?style=flat)](https://www.npmjs.org/package/redux-first-routing)

@@ -13,4 +13,20 @@ Achieve client-side routing *the Redux way*:

This library wraps [`history`](https://github.com/ReactTraining/history) and provides a framework-agnostic base for accomplishing Redux-first routing. For a complete routing solution, pair it with a compatible client-side routing library (see [Recipies](#recipies) for examples).
This library wraps [`history`](https://github.com/ReactTraining/history) and provides a minimal, framework-agnostic base for accomplishing Redux-first routing. **It does not provide the actual *router* component.**
Instead, you can pair it with a compatible client-side routing library from your framework of choice, to create a complete routing solution (see [Recipies](#recipies) for full examples).
## Installation
Using [npm](https://www.npmjs.org/package/redux-first-routing):
```
npm install --save redux-first-routing
```
Or, use the following script tag to access the [latest UMD build](https://unpkg.com/redux-first-routing/dist) on `window.ReduxFirstRouting`:
```html
<script src="https://unpkg.com/redux-first-routing/dist/redux-first-routing.min.js"></script>
```
## Recipies

@@ -25,5 +41,7 @@

There are dozens of ways to design the state shape of the location data, and this project by nature must choose a single, opinonated implementation. Here is the current design:
There are dozens of ways to design the state shape of the location data, and this project must by nature choose a single, opinonated design. Here is the current design:
```js
// window.location => www.example.com/nested/path?with=query#and-hash
{

@@ -40,3 +58,2 @@ ..., // other redux state

}
// current location: 'www.website.com/nested/path?with=query#and-hash'
```

@@ -43,0 +60,0 @@

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