1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-22 17:33:14 +01:00

Decorate rackt/history with history of previous locations

Could be turned into a createHistory enhancer function
(https://github.com/rackt/history/blob/master/docs/Glossary.md#createhis
toryenhancer), but we’ll see what the guys at rackt/history say about
it…
This commit is contained in:
Brett Sun 2016-01-08 11:44:25 +01:00
parent 2acf3f4056
commit fce578e854
3 changed files with 32 additions and 6 deletions

View File

@ -1,11 +1,14 @@
'use strict';
import React from 'react';
import { History } from 'react-router';
import Header from '../components/header';
import Footer from '../components/footer';
import Header from './header';
import Footer from './footer';
import GlobalNotification from './global_notification';
import AppConstants from '../constants/application_constants';
let AscribeApp = React.createClass({
propTypes: {
@ -13,11 +16,28 @@ let AscribeApp = React.createClass({
React.PropTypes.arrayOf(React.PropTypes.element),
React.PropTypes.element
]),
routes: React.PropTypes.arrayOf(React.PropTypes.object)
routes: React.PropTypes.arrayOf(React.PropTypes.object),
location: React.PropTypes.object
},
mixins: [History],
componentDidMount() {
this.history.locationQueue.push(this.props.location);
},
componentWillReceiveProps(nextProps) {
const { locationQueue } = this.history;
locationQueue.unshift(nextProps.location);
// Limit the number of locations to keep in memory to avoid too much memory usage
if (locationQueue.length > AppConstants.locationThreshold) {
locationQueue.length = AppConstants.locationThreshold;
}
},
render() {
let { children, routes } = this.props;
const { children, routes } = this.props;
return (
<div className="container ascribe-default-app">

View File

@ -104,6 +104,8 @@ const constants = {
'IVARO', 'SIAE', 'JASPAR-SPDA', 'AKKA/LAA', 'LATGA-A', 'SOMAAP', 'ARTEGESTION', 'CARIER', 'BONO', 'APSAV',
'SPA', 'GESTOR', 'VISaRTA', 'RAO', 'LITA', 'DALRO', 'VeGaP', 'BUS', 'ProLitteris', 'AGADU', 'AUTORARTE', 'BUBEDRA', 'BBDA', 'BCDA', 'BURIDA', 'ADAVIS', 'BSDA'],
'locationThreshold': 10,
'searchThreshold': 500,
'supportedThumbnailFileFormats': [

View File

@ -6,8 +6,12 @@ import AppConstants from './constants/application_constants';
// Remove the trailing slash if present
let baseUrl = AppConstants.baseUrl.replace(/\/$/, '');
const baseUrl = AppConstants.baseUrl.replace(/\/$/, '');
export default useBasename(createBrowserHistory)({
const history = useBasename(createBrowserHistory)({
basename: baseUrl
});
history.locationQueue = [];
export default history;