twreporter-react
Version:
React-Redux site for The Reporter Foundation in Taiwan
416 lines (339 loc) • 13.3 kB
JavaScript
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else if(typeof exports === 'object')
exports["ReactRouterRedux"] = factory();
else
root["ReactRouterRedux"] = factory();
})(this, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.routerMiddleware = exports.routerActions = exports.goForward = exports.goBack = exports.go = exports.replace = exports.push = exports.CALL_HISTORY_METHOD = exports.routerReducer = exports.LOCATION_CHANGE = exports.syncHistoryWithStore = undefined;
var _reducer = __webpack_require__(2);
Object.defineProperty(exports, 'LOCATION_CHANGE', {
enumerable: true,
get: function get() {
return _reducer.LOCATION_CHANGE;
}
});
Object.defineProperty(exports, 'routerReducer', {
enumerable: true,
get: function get() {
return _reducer.routerReducer;
}
});
var _actions = __webpack_require__(1);
Object.defineProperty(exports, 'CALL_HISTORY_METHOD', {
enumerable: true,
get: function get() {
return _actions.CALL_HISTORY_METHOD;
}
});
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, 'routerActions', {
enumerable: true,
get: function get() {
return _actions.routerActions;
}
});
var _sync = __webpack_require__(4);
var _sync2 = _interopRequireDefault(_sync);
var _middleware = __webpack_require__(3);
var _middleware2 = _interopRequireDefault(_middleware);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
exports.syncHistoryWithStore = _sync2['default'];
exports.routerMiddleware = _middleware2['default'];
/***/ },
/* 1 */
/***/ function(module, exports) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
/**
* This action type will be dispatched by the history actions below.
* If you're writing a middleware to watch for navigation events, be sure to
* look for actions of this type.
*/
var CALL_HISTORY_METHOD = exports.CALL_HISTORY_METHOD = '@@router/CALL_HISTORY_METHOD';
function updateLocation(method) {
return function () {
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return {
type: CALL_HISTORY_METHOD,
payload: { method: method, args: args }
};
};
}
/**
* These actions correspond to the history API.
* The associated routerMiddleware will capture these events before they get to
* your reducer and reissue them as the matching function on your history.
*/
var push = exports.push = updateLocation('push');
var replace = exports.replace = updateLocation('replace');
var go = exports.go = updateLocation('go');
var goBack = exports.goBack = updateLocation('goBack');
var goForward = exports.goForward = updateLocation('goForward');
var routerActions = exports.routerActions = { push: push, replace: replace, go: go, goBack: goBack, goForward: goForward };
/***/ },
/* 2 */
/***/ function(module, exports) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
exports.routerReducer = routerReducer;
/**
* This action type will be dispatched when your history
* receives a location change.
*/
var LOCATION_CHANGE = exports.LOCATION_CHANGE = '@@router/LOCATION_CHANGE';
var initialState = {
locationBeforeTransitions: null
};
/**
* This reducer will update the state with the most recent location history
* has transitioned to. This may not be in sync with the router, particularly
* if you have asynchronously-loaded routes, so reading from and relying on
* this state is discouraged.
*/
function routerReducer() {
var state = arguments.length <= 0 || arguments[0] === undefined ? initialState : arguments[0];
var _ref = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
var type = _ref.type;
var payload = _ref.payload;
if (type === LOCATION_CHANGE) {
return _extends({}, state, { locationBeforeTransitions: payload });
}
return state;
}
/***/ },
/* 3 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports['default'] = routerMiddleware;
var _actions = __webpack_require__(1);
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
/**
* This middleware captures CALL_HISTORY_METHOD actions to redirect to the
* provided history object. This will prevent these actions from reaching your
* reducer or any middleware that comes after this one.
*/
function routerMiddleware(history) {
return function () {
return function (next) {
return function (action) {
if (action.type !== _actions.CALL_HISTORY_METHOD) {
return next(action);
}
var _action$payload = action.payload;
var method = _action$payload.method;
var args = _action$payload.args;
history[method].apply(history, _toConsumableArray(args));
};
};
};
}
/***/ },
/* 4 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
exports['default'] = syncHistoryWithStore;
var _reducer = __webpack_require__(2);
var defaultSelectLocationState = function defaultSelectLocationState(state) {
return state.routing;
};
/**
* This function synchronizes your history state with the Redux store.
* Location changes flow from history to the store. An enhanced history is
* returned with a listen method that responds to store updates for location.
*
* When this history is provided to the router, this means the location data
* will flow like this:
* history.push -> store.dispatch -> enhancedHistory.listen -> router
* This ensures that when the store state changes due to a replay or other
* event, the router will be updated appropriately and can transition to the
* correct router state.
*/
function syncHistoryWithStore(history, store) {
var _ref = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
var _ref$selectLocationSt = _ref.selectLocationState;
var selectLocationState = _ref$selectLocationSt === undefined ? defaultSelectLocationState : _ref$selectLocationSt;
var _ref$adjustUrlOnRepla = _ref.adjustUrlOnReplay;
var adjustUrlOnReplay = _ref$adjustUrlOnRepla === undefined ? true : _ref$adjustUrlOnRepla;
// Ensure that the reducer is mounted on the store and functioning properly.
if (typeof selectLocationState(store.getState()) === 'undefined') {
throw new Error('Expected the routing state to be available either as `state.routing` ' + 'or as the custom expression you can specify as `selectLocationState` ' + 'in the `syncHistoryWithStore()` options. ' + 'Ensure you have added the `routerReducer` to your store\'s ' + 'reducers via `combineReducers` or whatever method you use to isolate ' + 'your reducers.');
}
var initialLocation = void 0;
var currentLocation = void 0;
var isTimeTraveling = void 0;
var unsubscribeFromStore = void 0;
var unsubscribeFromHistory = void 0;
// What does the store say about current location?
var getLocationInStore = function getLocationInStore(useInitialIfEmpty) {
var locationState = selectLocationState(store.getState());
return locationState.locationBeforeTransitions || (useInitialIfEmpty ? initialLocation : undefined);
};
// If the store is replayed, update the URL in the browser to match.
if (adjustUrlOnReplay) {
var handleStoreChange = function handleStoreChange() {
var locationInStore = getLocationInStore(true);
if (currentLocation === locationInStore) {
return;
}
// Update address bar to reflect store state
isTimeTraveling = true;
currentLocation = locationInStore;
history.transitionTo(_extends({}, locationInStore, {
action: 'PUSH'
}));
isTimeTraveling = false;
};
unsubscribeFromStore = store.subscribe(handleStoreChange);
handleStoreChange();
}
// Whenever location changes, dispatch an action to get it in the store
var handleLocationChange = function handleLocationChange(location) {
// ... unless we just caused that location change
if (isTimeTraveling) {
return;
}
// Remember where we are
currentLocation = location;
// Are we being called for the first time?
if (!initialLocation) {
// Remember as a fallback in case state is reset
initialLocation = location;
// Respect persisted location, if any
if (getLocationInStore()) {
return;
}
}
// Tell the store to update by dispatching an action
store.dispatch({
type: _reducer.LOCATION_CHANGE,
payload: location
});
};
unsubscribeFromHistory = history.listen(handleLocationChange);
// The enhanced history uses store as source of truth
return _extends({}, history, {
// The listeners are subscribed to the store instead of history
listen: function listen(listener) {
// Copy of last location.
var lastPublishedLocation = getLocationInStore(true);
// Keep track of whether we unsubscribed, as Redux store
// only applies changes in subscriptions on next dispatch
var unsubscribed = false;
var unsubscribeFromStore = store.subscribe(function () {
var currentLocation = getLocationInStore(true);
if (currentLocation === lastPublishedLocation) {
return;
}
lastPublishedLocation = currentLocation;
if (!unsubscribed) {
listener(lastPublishedLocation);
}
});
// History listeners expect a synchronous call. Make the first call to the
// listener after subscribing to the store, in case the listener causes a
// location change (e.g. when it redirects)
listener(lastPublishedLocation);
// Let user unsubscribe later
return function () {
unsubscribed = true;
unsubscribeFromStore();
};
},
// It also provides a way to destroy internal listeners
unsubscribe: function unsubscribe() {
if (adjustUrlOnReplay) {
unsubscribeFromStore();
}
unsubscribeFromHistory();
}
});
}
/***/ }
/******/ ])
});
;