Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Commit

Permalink
FIx gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
Blightwidow committed Sep 27, 2018
1 parent 905c93e commit 0f2f77f
Show file tree
Hide file tree
Showing 128 changed files with 7,689 additions and 2 deletions.
8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ packages
website

#For release only
.*rc
*.js
.babelrc
.eslintrc
tests.*.js
webpack.config.js
modules/
karma.conf.js
scripts/
83 changes: 83 additions & 0 deletions es/AsyncUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
export function loopAsync(turns, work, callback) {
var currentTurn = 0,
isDone = false;
var sync = false,
hasNext = false,
doneArgs = void 0;

function done() {
isDone = true;
if (sync) {
// Iterate instead of recursing if possible.
doneArgs = [].concat(Array.prototype.slice.call(arguments));
return;
}

callback.apply(this, arguments);
}

function next() {
if (isDone) {
return;
}

hasNext = true;
if (sync) {
// Iterate instead of recursing if possible.
return;
}

sync = true;

while (!isDone && currentTurn < turns && hasNext) {
hasNext = false;
work.call(this, currentTurn++, next, done);
}

sync = false;

if (isDone) {
// This means the loop finished synchronously.
callback.apply(this, doneArgs);
return;
}

if (currentTurn >= turns && hasNext) {
isDone = true;
callback();
}
}

next();
}

export function mapAsync(array, work, callback) {
var length = array.length;
var values = [];

if (length === 0) return callback(null, values);

var isDone = false,
doneCount = 0;

function done(index, error, value) {
if (isDone) return;

if (error) {
isDone = true;
callback(error);
} else {
values[index] = value;

isDone = ++doneCount === length;

if (isDone) callback(null, values);
}
}

array.forEach(function (item, index) {
work(item, index, function (error, value) {
done(index, error, value);
});
});
}
115 changes: 115 additions & 0 deletions es/ContextUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import PropTypes from 'prop-types';

// Works around issues with context updates failing to propagate.
// Caveat: the context value is expected to never change its identity.
// https://github.com/facebook/react/issues/2517
// https://github.com/reactjs/react-router/issues/470

var contextProviderShape = PropTypes.shape({
subscribe: PropTypes.func.isRequired,
eventIndex: PropTypes.number.isRequired
});

function makeContextName(name) {
return '@@contextSubscriber/' + name;
}

export function ContextProvider(name) {
var _childContextTypes, _ref2;

var contextName = makeContextName(name);
var listenersKey = contextName + '/listeners';
var eventIndexKey = contextName + '/eventIndex';
var subscribeKey = contextName + '/subscribe';

return _ref2 = {
childContextTypes: (_childContextTypes = {}, _childContextTypes[contextName] = contextProviderShape.isRequired, _childContextTypes),

getChildContext: function getChildContext() {
var _ref;

return _ref = {}, _ref[contextName] = {
eventIndex: this[eventIndexKey],
subscribe: this[subscribeKey]
}, _ref;
},
componentWillMount: function componentWillMount() {
this[listenersKey] = [];
this[eventIndexKey] = 0;
},
componentWillReceiveProps: function componentWillReceiveProps() {
this[eventIndexKey]++;
},
componentDidUpdate: function componentDidUpdate() {
var _this = this;

this[listenersKey].forEach(function (listener) {
return listener(_this[eventIndexKey]);
});
}
}, _ref2[subscribeKey] = function (listener) {
var _this2 = this;

// No need to immediately call listener here.
this[listenersKey].push(listener);

return function () {
_this2[listenersKey] = _this2[listenersKey].filter(function (item) {
return item !== listener;
});
};
}, _ref2;
}

export function ContextSubscriber(name) {
var _contextTypes, _ref4;

var contextName = makeContextName(name);
var lastRenderedEventIndexKey = contextName + '/lastRenderedEventIndex';
var handleContextUpdateKey = contextName + '/handleContextUpdate';
var unsubscribeKey = contextName + '/unsubscribe';

return _ref4 = {
contextTypes: (_contextTypes = {}, _contextTypes[contextName] = contextProviderShape, _contextTypes),

getInitialState: function getInitialState() {
var _ref3;

if (!this.context[contextName]) {
return {};
}

return _ref3 = {}, _ref3[lastRenderedEventIndexKey] = this.context[contextName].eventIndex, _ref3;
},
componentDidMount: function componentDidMount() {
if (!this.context[contextName]) {
return;
}

this[unsubscribeKey] = this.context[contextName].subscribe(this[handleContextUpdateKey]);
},
componentWillReceiveProps: function componentWillReceiveProps() {
var _setState;

if (!this.context[contextName]) {
return;
}

this.setState((_setState = {}, _setState[lastRenderedEventIndexKey] = this.context[contextName].eventIndex, _setState));
},
componentWillUnmount: function componentWillUnmount() {
if (!this[unsubscribeKey]) {
return;
}

this[unsubscribeKey]();
this[unsubscribeKey] = null;
}
}, _ref4[handleContextUpdateKey] = function (eventIndex) {
if (eventIndex !== this.state[lastRenderedEventIndexKey]) {
var _setState2;

this.setState((_setState2 = {}, _setState2[lastRenderedEventIndexKey] = eventIndex, _setState2));
}
}, _ref4;
}
18 changes: 18 additions & 0 deletions es/IndexLink.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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; };

import React from 'react';
import createReactClass from 'create-react-class';
import Link from './Link';

/**
* An <IndexLink> is used to link to an <IndexRoute>.
*/
var IndexLink = createReactClass({
displayName: 'IndexLink',

render: function render() {
return React.createElement(Link, _extends({}, this.props, { onlyActiveOnIndex: true }));
}
});

export default IndexLink;
40 changes: 40 additions & 0 deletions es/IndexRedirect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import createReactClass from 'create-react-class';
import { string, object } from 'prop-types';
import warning from './routerWarning';
import invariant from 'invariant';
import Redirect from './Redirect';
import { falsy } from './InternalPropTypes';

/**
* An <IndexRedirect> is used to redirect from an indexRoute.
*/
/* eslint-disable react/require-render-return */
var IndexRedirect = createReactClass({
displayName: 'IndexRedirect',

statics: {
createRouteFromReactElement: function createRouteFromReactElement(element, parentRoute) {
/* istanbul ignore else: sanity check */
if (parentRoute) {
parentRoute.indexRoute = Redirect.createRouteFromReactElement(element);
} else {
process.env.NODE_ENV !== 'production' ? warning(false, 'An <IndexRedirect> does not make sense at the root of your route config') : void 0;
}
}
},

propTypes: {
to: string.isRequired,
query: object,
state: object,
onEnter: falsy,
children: falsy
},

/* istanbul ignore next: sanity check */
render: function render() {
!false ? process.env.NODE_ENV !== 'production' ? invariant(false, '<IndexRedirect> elements are for router configuration only and should not be rendered') : invariant(false) : void 0;
}
});

export default IndexRedirect;
41 changes: 41 additions & 0 deletions es/IndexRoute.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import createReactClass from 'create-react-class';
import { func } from 'prop-types';
import warning from './routerWarning';
import invariant from 'invariant';
import { createRouteFromReactElement as _createRouteFromReactElement } from './RouteUtils';
import { component, components, falsy } from './InternalPropTypes';

/**
* An <IndexRoute> is used to specify its parent's <Route indexRoute> in
* a JSX route config.
*/
/* eslint-disable react/require-render-return */
var IndexRoute = createReactClass({
displayName: 'IndexRoute',

statics: {
createRouteFromReactElement: function createRouteFromReactElement(element, parentRoute) {
/* istanbul ignore else: sanity check */
if (parentRoute) {
parentRoute.indexRoute = _createRouteFromReactElement(element);
} else {
process.env.NODE_ENV !== 'production' ? warning(false, 'An <IndexRoute> does not make sense at the root of your route config') : void 0;
}
}
},

propTypes: {
path: falsy,
component: component,
components: components,
getComponent: func,
getComponents: func
},

/* istanbul ignore next: sanity check */
render: function render() {
!false ? process.env.NODE_ENV !== 'production' ? invariant(false, '<IndexRoute> elements are for router configuration only and should not be rendered') : invariant(false) : void 0;
}
});

export default IndexRoute;
19 changes: 19 additions & 0 deletions es/InternalPropTypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { func, object, arrayOf, oneOfType, element, shape, string } from 'prop-types';

export function falsy(props, propName, componentName) {
if (props[propName]) return new Error('<' + componentName + '> should not have a "' + propName + '" prop');
}

export var history = shape({
listen: func.isRequired,
push: func.isRequired,
replace: func.isRequired,
go: func.isRequired,
goBack: func.isRequired,
goForward: func.isRequired
});

export var component = oneOfType([func, string]);
export var components = oneOfType([component, object]);
export var route = oneOfType([object, element]);
export var routes = oneOfType([route, arrayOf(route)]);
Loading

0 comments on commit 0f2f77f

Please sign in to comment.