initial commit taken from gitlab.lrz.de

This commit is contained in:
privatereese
2018-08-24 18:09:42 +02:00
parent ae54ed4c48
commit fc05486403
28494 changed files with 2159823 additions and 0 deletions

109
node_modules/react-proxy/README.md generated vendored Normal file
View File

@@ -0,0 +1,109 @@
# React Proxy [![build status](https://img.shields.io/travis/gaearon/react-proxy/master.svg?style=flat-square)](https://travis-ci.org/gaearon/react-proxy) [![npm version](https://img.shields.io/npm/v/react-proxy.svg?style=flat-square)](https://www.npmjs.com/package/react-proxy)
A generic React component proxy used as the new engine by React Hot Loader.
## 1.x and 2.x
You are looking at the README from the 1.x branch that is widely in use. However we intend to gradually transition projects such as `react-transform-hmr` to use [2.x that is being developed in master](https://github.com/gaearon/react-proxy/tree/master) instead. Currently we mirror all releases on both branches.
## Requirements
* React 0.13+
## Usage
Intended to be used from hot reloading tools like React Hot Loader.
If youre an application developer, its unlikely youll want to use it directly.
```js
import React, { Component } from 'react';
class ComponentVersion1 extends Component {
render() {
return <div>Before hot update.</div>;
}
}
class ComponentVersion2 extends Component {
render() {
return <div>After hot update.</div>;
}
}
```
Without React Proxy:
```js
const rootEl = document.getElementById('root');
React.render(<ComponentVersion1 />, rootEl);
// Will reset state and kill DOM :-(
React.render(<ComponentVersion2 />, rootEl);
```
With React Proxy:
```js
import { createProxy, getForceUpdate } from 'react-proxy';
// Create a proxy object, given the initial React component class.
const proxy = createProxy(ComponentVersion1);
// Obtain a React class that acts exactly like the initial version.
// This is what we'll use in our app instead of the real component class.
const Proxy = proxy.get();
// Render the component (proxy, really).
React.render(<Proxy />, rootEl);
// Point the proxy to the new React component class by calling update().
// Instances will stay mounted and their state will be intact, but their methods will be updated.
// The update() method returns an array of mounted instances so we can do something with them.
const mountedInstances = proxy.update(ComponentVersion2);
// React Proxy also provides us with getForceUpdate() method that works even if the component
// instance doesn't descend from React.Component, and doesn't have a forceUpdate() method.
const forceUpdate = getForceUpdate(React);
// Force-update all the affected instances!
mountedInstances.forEach(forceUpdate);
```
## Features
* Supports both classic (`React.createClass()`) and modern (ES6 classes) style
* Supports classes that dont descend from `React.Component`
* Supports classes with strict `shouldComponentUpdate`
* Supports inherited and base classes (although you shouldnt use inheritance with React)
* Supports classic `createClass()` autobinding and modern [`autobind-decorator`](https://github.com/andreypopp/autobind-decorator)
* Contains an extensive test suite to avoid regressions
* Preserves `displayName`
* Preserves enumerability and writability of methods
* Preserves `toString()` of methods
* Replaces instance getters and setters
* Replaces instance methods preserving their identity
* Replaces bound instance methods preserving their identity
* Because identity is preserved, instance methods already scheduled for `setInterval` or `setTimeout` are updated
* Replaces static getters and setters
* Replaces unbound static methods
* Replaces static properties unless they were overwritten by code
## Known Limitations
* Does not replace ES7 instance properties
* Does not replace bound static methods
* Replacing a method using [`autobind-decorator`](https://github.com/andreypopp/autobind-decorator) causes its identity to change
## Contributing
1. Clone the repository
2. Run `npm install`
3. Run `npm run test:watch`
4. Take a look at the existing tests
5. Add tests for the failing case you aim to fix and make them pass
6. Submit a PR!
## License
MIT

4893
node_modules/react-proxy/dist/ReactProxy.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,93 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = bindAutoBindMethods;
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of React source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* Original:
* https://github.com/facebook/react/blob/6508b1ad273a6f371e8d90ae676e5390199461b4/src/isomorphic/classic/class/ReactClass.js#L650-L713
*/
function bindAutoBindMethod(component, method) {
var boundMethod = method.bind(component);
boundMethod.__reactBoundContext = component;
boundMethod.__reactBoundMethod = method;
boundMethod.__reactBoundArguments = null;
var componentName = component.constructor.displayName,
_bind = boundMethod.bind;
boundMethod.bind = function (newThis) {
var args = Array.prototype.slice.call(arguments, 1);
if (newThis !== component && newThis !== null) {
console.warn('bind(): React component methods may only be bound to the ' + 'component instance. See ' + componentName);
} else if (!args.length) {
console.warn('bind(): You are binding a component method to the component. ' + 'React does this for you automatically in a high-performance ' + 'way, so you can safely remove this call. See ' + componentName);
return boundMethod;
}
var reboundMethod = _bind.apply(boundMethod, arguments);
reboundMethod.__reactBoundContext = component;
reboundMethod.__reactBoundMethod = method;
reboundMethod.__reactBoundArguments = args;
return reboundMethod;
};
return boundMethod;
}
function bindAutoBindMethodsFromMap(component) {
for (var autoBindKey in component.__reactAutoBindMap) {
if (!component.__reactAutoBindMap.hasOwnProperty(autoBindKey)) {
return;
}
// Tweak: skip methods that are already bound.
// This is to preserve method reference in case it is used
// as a subscription handler that needs to be detached later.
if (component.hasOwnProperty(autoBindKey) && component[autoBindKey].__reactBoundContext === component) {
continue;
}
var method = component.__reactAutoBindMap[autoBindKey];
component[autoBindKey] = bindAutoBindMethod(component, method);
}
}
function bindAutoBindMethods(component) {
if (component.__reactAutoBindPairs) {
bindAutoBindMethodsFromArray(component);
} else if (component.__reactAutoBindMap) {
bindAutoBindMethodsFromMap(component);
}
}
function bindAutoBindMethodsFromArray(component) {
var pairs = component.__reactAutoBindPairs;
if (!pairs) {
return;
}
for (var i = 0; i < pairs.length; i += 2) {
var autoBindKey = pairs[i];
if (component.hasOwnProperty(autoBindKey) && component[autoBindKey].__reactBoundContext === component) {
continue;
}
var method = pairs[i + 1];
component[autoBindKey] = bindAutoBindMethod(component, method);
}
}

245
node_modules/react-proxy/modules/createClassProxy.js generated vendored Normal file
View File

@@ -0,0 +1,245 @@
'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; };
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
exports.default = proxyClass;
exports.default = createClassProxy;
var _find = require('lodash/find');
var _find2 = _interopRequireDefault(_find);
var _createPrototypeProxy = require('./createPrototypeProxy');
var _createPrototypeProxy2 = _interopRequireDefault(_createPrototypeProxy);
var _bindAutoBindMethods = require('./bindAutoBindMethods');
var _bindAutoBindMethods2 = _interopRequireDefault(_bindAutoBindMethods);
var _deleteUnknownAutoBindMethods = require('./deleteUnknownAutoBindMethods');
var _deleteUnknownAutoBindMethods2 = _interopRequireDefault(_deleteUnknownAutoBindMethods);
var _supportsProtoAssignment = require('./supportsProtoAssignment');
var _supportsProtoAssignment2 = _interopRequireDefault(_supportsProtoAssignment);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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); } }
var RESERVED_STATICS = ['length', 'name', 'arguments', 'caller', 'prototype', 'toString'];
function isEqualDescriptor(a, b) {
if (!a && !b) {
return true;
}
if (!a || !b) {
return false;
}
for (var key in a) {
if (a[key] !== b[key]) {
return false;
}
}
return true;
}
// This was originally a WeakMap but we had issues with React Native:
// https://github.com/gaearon/react-proxy/issues/50#issuecomment-192928066
var allProxies = [];
function findProxy(Component) {
var pair = (0, _find2.default)(allProxies, function (_ref) {
var _ref2 = _slicedToArray(_ref, 1);
var key = _ref2[0];
return key === Component;
});
return pair ? pair[1] : null;
}
function addProxy(Component, proxy) {
allProxies.push([Component, proxy]);
}
function proxyClass(InitialComponent) {
// Prevent double wrapping.
// Given a proxy class, return the existing proxy managing it.
var existingProxy = findProxy(InitialComponent);
if (existingProxy) {
return existingProxy;
}
var prototypeProxy = (0, _createPrototypeProxy2.default)();
var CurrentComponent = undefined;
var ProxyComponent = undefined;
var staticDescriptors = {};
function wasStaticModifiedByUser(key) {
// Compare the descriptor with the one we previously set ourselves.
var currentDescriptor = Object.getOwnPropertyDescriptor(ProxyComponent, key);
return !isEqualDescriptor(staticDescriptors[key], currentDescriptor);
}
function instantiate(factory, context, params) {
var component = factory();
try {
return component.apply(context, params);
} catch (err) {
(function () {
// Native ES6 class instantiation
var instance = new (Function.prototype.bind.apply(component, [null].concat(_toConsumableArray(params))))();
Object.keys(instance).forEach(function (key) {
if (RESERVED_STATICS.indexOf(key) > -1) {
return;
}
context[key] = instance[key];
});
})();
}
}
try {
// Create a proxy constructor with matching name
ProxyComponent = new Function('factory', 'instantiate', 'return function ' + (InitialComponent.name || 'ProxyComponent') + '() {\n return instantiate(factory, this, arguments);\n }')(function () {
return CurrentComponent;
}, instantiate);
} catch (err) {
// Some environments may forbid dynamic evaluation
ProxyComponent = function ProxyComponent() {
return instantiate(function () {
return CurrentComponent;
}, this, arguments);
};
}
// Point proxy constructor to the proxy prototype
ProxyComponent.prototype = prototypeProxy.get();
// Proxy toString() to the current constructor
ProxyComponent.toString = function toString() {
return CurrentComponent.toString();
};
function update(NextComponent) {
if (typeof NextComponent !== 'function') {
throw new Error('Expected a constructor.');
}
// Prevent proxy cycles
var existingProxy = findProxy(NextComponent);
if (existingProxy) {
return update(existingProxy.__getCurrent());
}
// Save the next constructor so we call it
CurrentComponent = NextComponent;
// Update the prototype proxy with new methods
var mountedInstances = prototypeProxy.update(NextComponent.prototype);
// Set up the constructor property so accessing the statics work
ProxyComponent.prototype.constructor = ProxyComponent;
// Set up the same prototype for inherited statics
ProxyComponent.__proto__ = NextComponent.__proto__;
// Copy static methods and properties
Object.getOwnPropertyNames(NextComponent).forEach(function (key) {
if (RESERVED_STATICS.indexOf(key) > -1) {
return;
}
var staticDescriptor = _extends({}, Object.getOwnPropertyDescriptor(NextComponent, key), {
configurable: true
});
// Copy static unless user has redefined it at runtime
if (!wasStaticModifiedByUser(key)) {
Object.defineProperty(ProxyComponent, key, staticDescriptor);
staticDescriptors[key] = staticDescriptor;
}
});
// Remove old static methods and properties
Object.getOwnPropertyNames(ProxyComponent).forEach(function (key) {
if (RESERVED_STATICS.indexOf(key) > -1) {
return;
}
// Skip statics that exist on the next class
if (NextComponent.hasOwnProperty(key)) {
return;
}
// Skip non-configurable statics
var descriptor = Object.getOwnPropertyDescriptor(ProxyComponent, key);
if (descriptor && !descriptor.configurable) {
return;
}
// Delete static unless user has redefined it at runtime
if (!wasStaticModifiedByUser(key)) {
delete ProxyComponent[key];
delete staticDescriptors[key];
}
});
// Try to infer displayName
ProxyComponent.displayName = NextComponent.displayName || NextComponent.name;
// We might have added new methods that need to be auto-bound
mountedInstances.forEach(_bindAutoBindMethods2.default);
mountedInstances.forEach(_deleteUnknownAutoBindMethods2.default);
// Let the user take care of redrawing
return mountedInstances;
};
function get() {
return ProxyComponent;
}
function getCurrent() {
return CurrentComponent;
}
update(InitialComponent);
var proxy = { get: get, update: update };
addProxy(ProxyComponent, proxy);
Object.defineProperty(proxy, '__getCurrent', {
configurable: false,
writable: false,
enumerable: false,
value: getCurrent
});
return proxy;
}
function createFallback(Component) {
var CurrentComponent = Component;
return {
get: function get() {
return CurrentComponent;
},
update: function update(NextComponent) {
CurrentComponent = NextComponent;
}
};
}
function createClassProxy(Component) {
return Component.__proto__ && (0, _supportsProtoAssignment2.default)() ? proxyClass(Component) : createFallback(Component);
}

View File

@@ -0,0 +1,202 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = createPrototypeProxy;
var _assign = require('lodash/assign');
var _assign2 = _interopRequireDefault(_assign);
var _difference = require('lodash/difference');
var _difference2 = _interopRequireDefault(_difference);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function createPrototypeProxy() {
var proxy = {};
var current = null;
var mountedInstances = [];
/**
* Creates a proxied toString() method pointing to the current version's toString().
*/
function proxyToString(name) {
// Wrap to always call the current version
return function toString() {
if (typeof current[name] === 'function') {
return current[name].toString();
} else {
return '<method was deleted>';
}
};
}
/**
* Creates a proxied method that calls the current version, whenever available.
*/
function proxyMethod(name) {
// Wrap to always call the current version
var proxiedMethod = function proxiedMethod() {
if (typeof current[name] === 'function') {
return current[name].apply(this, arguments);
}
};
// Copy properties of the original function, if any
(0, _assign2.default)(proxiedMethod, current[name]);
proxiedMethod.toString = proxyToString(name);
return proxiedMethod;
}
/**
* Augments the original componentDidMount with instance tracking.
*/
function proxiedComponentDidMount() {
mountedInstances.push(this);
if (typeof current.componentDidMount === 'function') {
return current.componentDidMount.apply(this, arguments);
}
}
proxiedComponentDidMount.toString = proxyToString('componentDidMount');
/**
* Augments the original componentWillUnmount with instance tracking.
*/
function proxiedComponentWillUnmount() {
var index = mountedInstances.indexOf(this);
// Unless we're in a weird environment without componentDidMount
if (index !== -1) {
mountedInstances.splice(index, 1);
}
if (typeof current.componentWillUnmount === 'function') {
return current.componentWillUnmount.apply(this, arguments);
}
}
proxiedComponentWillUnmount.toString = proxyToString('componentWillUnmount');
/**
* Defines a property on the proxy.
*/
function defineProxyProperty(name, descriptor) {
Object.defineProperty(proxy, name, descriptor);
}
/**
* Defines a property, attempting to keep the original descriptor configuration.
*/
function defineProxyPropertyWithValue(name, value) {
var _ref = Object.getOwnPropertyDescriptor(current, name) || {};
var _ref$enumerable = _ref.enumerable;
var enumerable = _ref$enumerable === undefined ? false : _ref$enumerable;
var _ref$writable = _ref.writable;
var writable = _ref$writable === undefined ? true : _ref$writable;
defineProxyProperty(name, {
configurable: true,
enumerable: enumerable,
writable: writable,
value: value
});
}
/**
* Creates an auto-bind map mimicking the original map, but directed at proxy.
*/
function createAutoBindMap() {
if (!current.__reactAutoBindMap) {
return;
}
var __reactAutoBindMap = {};
for (var name in current.__reactAutoBindMap) {
if (typeof proxy[name] === 'function' && current.__reactAutoBindMap.hasOwnProperty(name)) {
__reactAutoBindMap[name] = proxy[name];
}
}
return __reactAutoBindMap;
}
/**
* Creates an auto-bind map mimicking the original map, but directed at proxy.
*/
function createAutoBindPairs() {
var __reactAutoBindPairs = [];
for (var i = 0; i < current.__reactAutoBindPairs.length; i += 2) {
var name = current.__reactAutoBindPairs[i];
var method = proxy[name];
if (typeof method === 'function') {
__reactAutoBindPairs.push(name, method);
}
}
return __reactAutoBindPairs;
}
/**
* Applies the updated prototype.
*/
function update(next) {
// Save current source of truth
current = next;
// Find changed property names
var currentNames = Object.getOwnPropertyNames(current);
var previousName = Object.getOwnPropertyNames(proxy);
var removedNames = (0, _difference2.default)(previousName, currentNames);
// Remove properties and methods that are no longer there
removedNames.forEach(function (name) {
delete proxy[name];
});
// Copy every descriptor
currentNames.forEach(function (name) {
var descriptor = Object.getOwnPropertyDescriptor(current, name);
if (typeof descriptor.value === 'function') {
// Functions require additional wrapping so they can be bound later
defineProxyPropertyWithValue(name, proxyMethod(name));
} else {
// Other values can be copied directly
defineProxyProperty(name, descriptor);
}
});
// Track mounting and unmounting
defineProxyPropertyWithValue('componentDidMount', proxiedComponentDidMount);
defineProxyPropertyWithValue('componentWillUnmount', proxiedComponentWillUnmount);
if (current.hasOwnProperty('__reactAutoBindMap')) {
defineProxyPropertyWithValue('__reactAutoBindMap', createAutoBindMap());
}
if (current.hasOwnProperty('__reactAutoBindPairs')) {
defineProxyPropertyWithValue('__reactAutoBindPairs', createAutoBindPairs());
}
// Set up the prototype chain
proxy.__proto__ = next;
return mountedInstances;
}
/**
* Returns the up-to-date proxy prototype.
*/
function get() {
return proxy;
}
return {
update: update,
get: get
};
};

View File

@@ -0,0 +1,83 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = deleteUnknownAutoBindMethods;
function shouldDeleteClassicInstanceMethod(component, name) {
if (component.__reactAutoBindMap && component.__reactAutoBindMap.hasOwnProperty(name)) {
// It's a known autobound function, keep it
return false;
}
if (component.__reactAutoBindPairs && component.__reactAutoBindPairs.indexOf(name) >= 0) {
// It's a known autobound function, keep it
return false;
}
if (component[name].__reactBoundArguments !== null) {
// It's a function bound to specific args, keep it
return false;
}
// It's a cached bound method for a function
// that was deleted by user, so we delete it from component.
return true;
}
function shouldDeleteModernInstanceMethod(component, name) {
var prototype = component.constructor.prototype;
var prototypeDescriptor = Object.getOwnPropertyDescriptor(prototype, name);
if (!prototypeDescriptor || !prototypeDescriptor.get) {
// This is definitely not an autobinding getter
return false;
}
if (prototypeDescriptor.get().length !== component[name].length) {
// The length doesn't match, bail out
return false;
}
// This seems like a method bound using an autobinding getter on the prototype
// Hopefully we won't run into too many false positives.
return true;
}
function shouldDeleteInstanceMethod(component, name) {
var descriptor = Object.getOwnPropertyDescriptor(component, name);
if (typeof descriptor.value !== 'function') {
// Not a function, or something fancy: bail out
return;
}
if (component.__reactAutoBindMap || component.__reactAutoBindPairs) {
// Classic
return shouldDeleteClassicInstanceMethod(component, name);
} else {
// Modern
return shouldDeleteModernInstanceMethod(component, name);
}
}
/**
* Deletes autobound methods from the instance.
*
* For classic React classes, we only delete the methods that no longer exist in map.
* This means the user actually deleted them in code.
*
* For modern classes, we delete methods that exist on prototype with the same length,
* and which have getters on prototype, but are normal values on the instance.
* This is usually an indication that an autobinding decorator is being used,
* and the getter will re-generate the memoized handler on next access.
*/
function deleteUnknownAutoBindMethods(component) {
var names = Object.getOwnPropertyNames(component);
names.forEach(function (name) {
if (shouldDeleteInstanceMethod(component, name)) {
delete component[name];
}
});
}

27
node_modules/react-proxy/modules/index.js generated vendored Normal file
View File

@@ -0,0 +1,27 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getForceUpdate = exports.createProxy = undefined;
var _supportsProtoAssignment = require('./supportsProtoAssignment');
var _supportsProtoAssignment2 = _interopRequireDefault(_supportsProtoAssignment);
var _createClassProxy = require('./createClassProxy');
var _createClassProxy2 = _interopRequireDefault(_createClassProxy);
var _reactDeepForceUpdate = require('react-deep-force-update');
var _reactDeepForceUpdate2 = _interopRequireDefault(_reactDeepForceUpdate);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
if (!(0, _supportsProtoAssignment2.default)()) {
console.warn('This JavaScript environment does not support __proto__. ' + 'This means that react-proxy is unable to proxy React components. ' + 'Features that rely on react-proxy, such as react-transform-hmr, ' + 'will not function as expected.');
}
exports.createProxy = _createClassProxy2.default;
exports.getForceUpdate = _reactDeepForceUpdate2.default;

View File

@@ -0,0 +1,15 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = supportsProtoAssignment;
var x = {};
var y = { supports: true };
try {
x.__proto__ = y;
} catch (err) {}
function supportsProtoAssignment() {
return x.supports || false;
};

127
node_modules/react-proxy/package.json generated vendored Normal file
View File

@@ -0,0 +1,127 @@
{
"_args": [
[
"react-proxy@^1.1.7",
"/home/bernhard/freifunk-app/node_modules/react-transform-hmr"
]
],
"_from": "react-proxy@>=1.1.7 <2.0.0",
"_id": "react-proxy@1.1.8",
"_inCache": true,
"_installable": true,
"_location": "/react-proxy",
"_nodeVersion": "5.3.0",
"_npmOperationalInternal": {
"host": "packages-12-west.internal.npmjs.com",
"tmp": "tmp/react-proxy-1.1.8.tgz_1457572557360_0.7841383838094771"
},
"_npmUser": {
"email": "dan.abramov@gmail.com",
"name": "gaearon"
},
"_npmVersion": "3.3.12",
"_phantomChildren": {},
"_requested": {
"name": "react-proxy",
"raw": "react-proxy@^1.1.7",
"rawSpec": "^1.1.7",
"scope": null,
"spec": ">=1.1.7 <2.0.0",
"type": "range"
},
"_requiredBy": [
"/react-transform-hmr"
],
"_resolved": "https://registry.npmjs.org/react-proxy/-/react-proxy-1.1.8.tgz",
"_shasum": "9dbfd9d927528c3aa9f444e4558c37830ab8c26a",
"_shrinkwrap": null,
"_spec": "react-proxy@^1.1.7",
"_where": "/home/bernhard/freifunk-app/node_modules/react-transform-hmr",
"author": {
"email": "dan.abramov@me.com",
"name": "Dan Abramov",
"url": "http://github.com/gaearon"
},
"bugs": {
"url": "https://github.com/gaearon/react-proxy/issues"
},
"dependencies": {
"lodash": "^4.6.1",
"react-deep-force-update": "^1.0.0"
},
"description": "Proxies React components without unmounting or losing their state.",
"devDependencies": {
"babel-cli": "^6.3.17",
"babel-core": "^6.3.21",
"babel-loader": "^6.2.0",
"babel-plugin-check-es2015-constants": "^6.3.13",
"babel-plugin-syntax-jsx": "^6.3.13",
"babel-plugin-transform-class-properties": "^6.5.0",
"babel-plugin-transform-decorators-legacy": "^1.2.0",
"babel-plugin-transform-es2015-arrow-functions": "^6.3.13",
"babel-plugin-transform-es2015-block-scoped-functions": "^6.3.13",
"babel-plugin-transform-es2015-block-scoping": "^6.3.13",
"babel-plugin-transform-es2015-classes": "^6.3.13",
"babel-plugin-transform-es2015-computed-properties": "^6.3.13",
"babel-plugin-transform-es2015-destructuring": "^6.3.13",
"babel-plugin-transform-es2015-for-of": "^6.3.13",
"babel-plugin-transform-es2015-function-name": "^6.3.13",
"babel-plugin-transform-es2015-literals": "^6.3.13",
"babel-plugin-transform-es2015-modules-commonjs": "^6.3.13",
"babel-plugin-transform-es2015-object-super": "^6.3.13",
"babel-plugin-transform-es2015-parameters": "^6.3.13",
"babel-plugin-transform-es2015-shorthand-properties": "^6.3.13",
"babel-plugin-transform-es2015-spread": "^6.3.13",
"babel-plugin-transform-es2015-sticky-regex": "^6.3.13",
"babel-plugin-transform-es2015-template-literals": "^6.3.13",
"babel-plugin-transform-es2015-unicode-regex": "^6.3.13",
"babel-plugin-transform-flow-strip-types": "^6.5.0",
"babel-plugin-transform-object-rest-spread": "^6.3.13",
"babel-plugin-transform-react-display-name": "^6.4.0",
"babel-plugin-transform-react-jsx": "^6.4.0",
"babel-preset-es2015": "^6.6.0",
"babel-preset-react": "^6.5.0",
"expect": "^1.9.0",
"mocha": "^2.2.4",
"react": "^0.13.2",
"rimraf": "^2.4.2",
"webpack": "1.4.8"
},
"directories": {},
"dist": {
"shasum": "9dbfd9d927528c3aa9f444e4558c37830ab8c26a",
"tarball": "https://registry.npmjs.org/react-proxy/-/react-proxy-1.1.8.tgz"
},
"files": [
"dist",
"modules",
"src"
],
"gitHead": "13f076b17b43a9d53c151931f3629ef1baae42e5",
"homepage": "https://github.com/gaearon/react-proxy",
"license": "MIT",
"main": "modules/index.js",
"maintainers": [
{
"name": "gaearon",
"email": "dan.abramov@gmail.com"
}
],
"name": "react-proxy",
"optionalDependencies": {},
"readme": "ERROR: No README data found!",
"repository": {
"type": "git",
"url": "git+https://github.com/gaearon/react-proxy.git"
},
"scripts": {
"build": "rimraf modules dist && NODE_ENV=babel-es2015 webpack && NODE_ENV=babel-es2015 babel src --out-dir modules",
"prepublish": "npm run build && npm test",
"test": "npm run test:babel-es2015 && npm run test:native-es2015",
"test:babel-es2015": "NODE_ENV=babel-es2015 mocha --compilers js:babel-core/register --recursive ./test",
"test:native-es2015": "NODE_ENV=native-es2015 mocha --compilers js:babel-core/register --recursive ./test",
"test:native-es2015:watch": "npm run test:native-es2015 -- --watch",
"test:watch": "npm run test:babel-es2015 -- --watch"
},
"version": "1.1.8"
}

103
node_modules/react-proxy/src/bindAutoBindMethods.js generated vendored Normal file
View File

@@ -0,0 +1,103 @@
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of React source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* Original:
* https://github.com/facebook/react/blob/6508b1ad273a6f371e8d90ae676e5390199461b4/src/isomorphic/classic/class/ReactClass.js#L650-L713
*/
function bindAutoBindMethod(component, method) {
var boundMethod = method.bind(component);
boundMethod.__reactBoundContext = component;
boundMethod.__reactBoundMethod = method;
boundMethod.__reactBoundArguments = null;
var componentName = component.constructor.displayName,
_bind = boundMethod.bind;
boundMethod.bind = function (newThis) {
var args = Array.prototype.slice.call(arguments, 1);
if (newThis !== component && newThis !== null) {
console.warn(
'bind(): React component methods may only be bound to the ' +
'component instance. See ' + componentName
);
} else if (!args.length) {
console.warn(
'bind(): You are binding a component method to the component. ' +
'React does this for you automatically in a high-performance ' +
'way, so you can safely remove this call. See ' + componentName
);
return boundMethod;
}
var reboundMethod = _bind.apply(boundMethod, arguments);
reboundMethod.__reactBoundContext = component;
reboundMethod.__reactBoundMethod = method;
reboundMethod.__reactBoundArguments = args;
return reboundMethod;
};
return boundMethod;
}
function bindAutoBindMethodsFromMap(component) {
for (var autoBindKey in component.__reactAutoBindMap) {
if (!component.__reactAutoBindMap.hasOwnProperty(autoBindKey)) {
return;
}
// Tweak: skip methods that are already bound.
// This is to preserve method reference in case it is used
// as a subscription handler that needs to be detached later.
if (
component.hasOwnProperty(autoBindKey) &&
component[autoBindKey].__reactBoundContext === component
) {
continue;
}
var method = component.__reactAutoBindMap[autoBindKey];
component[autoBindKey] = bindAutoBindMethod(component, method);
}
}
export default function bindAutoBindMethods(component) {
if (component.__reactAutoBindPairs) {
bindAutoBindMethodsFromArray(component);
} else if (component.__reactAutoBindMap) {
bindAutoBindMethodsFromMap(component);
}
}
function bindAutoBindMethodsFromArray(component) {
var pairs = component.__reactAutoBindPairs;
if (!pairs) {
return;
}
for (var i = 0; i < pairs.length; i += 2) {
var autoBindKey = pairs[i];
if (
component.hasOwnProperty(autoBindKey) &&
component[autoBindKey].__reactBoundContext === component
) {
continue;
}
var method = pairs[i + 1];
component[autoBindKey] = bindAutoBindMethod(
component,
method
);
}
}

217
node_modules/react-proxy/src/createClassProxy.js generated vendored Normal file
View File

@@ -0,0 +1,217 @@
import find from 'lodash/find';
import createPrototypeProxy from './createPrototypeProxy';
import bindAutoBindMethods from './bindAutoBindMethods';
import deleteUnknownAutoBindMethods from './deleteUnknownAutoBindMethods';
import supportsProtoAssignment from './supportsProtoAssignment';
const RESERVED_STATICS = [
'length',
'name',
'arguments',
'caller',
'prototype',
'toString'
];
function isEqualDescriptor(a, b) {
if (!a && !b) {
return true;
}
if (!a || !b) {
return false;
}
for (let key in a) {
if (a[key] !== b[key]) {
return false;
}
}
return true;
}
// This was originally a WeakMap but we had issues with React Native:
// https://github.com/gaearon/react-proxy/issues/50#issuecomment-192928066
let allProxies = [];
function findProxy(Component) {
const pair = find(allProxies, ([key]) => key === Component);
return pair ? pair[1] : null;
}
function addProxy(Component, proxy) {
allProxies.push([Component, proxy]);
}
export default function proxyClass(InitialComponent) {
// Prevent double wrapping.
// Given a proxy class, return the existing proxy managing it.
var existingProxy = findProxy(InitialComponent);
if (existingProxy) {
return existingProxy;
}
const prototypeProxy = createPrototypeProxy();
let CurrentComponent;
let ProxyComponent;
let staticDescriptors = {};
function wasStaticModifiedByUser(key) {
// Compare the descriptor with the one we previously set ourselves.
const currentDescriptor = Object.getOwnPropertyDescriptor(ProxyComponent, key);
return !isEqualDescriptor(staticDescriptors[key], currentDescriptor);
}
function instantiate(factory, context, params) {
const component = factory();
try {
return component.apply(context, params);
} catch (err) {
// Native ES6 class instantiation
const instance = new component(...params);
Object.keys(instance).forEach(key => {
if (RESERVED_STATICS.indexOf(key) > -1) {
return;
}
context[key] = instance[key];
})
}
}
try {
// Create a proxy constructor with matching name
ProxyComponent = new Function('factory', 'instantiate',
`return function ${InitialComponent.name || 'ProxyComponent'}() {
return instantiate(factory, this, arguments);
}`
)(() => CurrentComponent, instantiate);
} catch (err) {
// Some environments may forbid dynamic evaluation
ProxyComponent = function () {
return instantiate(() => CurrentComponent, this, arguments);
};
}
// Point proxy constructor to the proxy prototype
ProxyComponent.prototype = prototypeProxy.get();
// Proxy toString() to the current constructor
ProxyComponent.toString = function toString() {
return CurrentComponent.toString();
};
function update(NextComponent) {
if (typeof NextComponent !== 'function') {
throw new Error('Expected a constructor.');
}
// Prevent proxy cycles
var existingProxy = findProxy(NextComponent);
if (existingProxy) {
return update(existingProxy.__getCurrent());
}
// Save the next constructor so we call it
CurrentComponent = NextComponent;
// Update the prototype proxy with new methods
const mountedInstances = prototypeProxy.update(NextComponent.prototype);
// Set up the constructor property so accessing the statics work
ProxyComponent.prototype.constructor = ProxyComponent;
// Set up the same prototype for inherited statics
ProxyComponent.__proto__ = NextComponent.__proto__;
// Copy static methods and properties
Object.getOwnPropertyNames(NextComponent).forEach(key => {
if (RESERVED_STATICS.indexOf(key) > -1) {
return;
}
const staticDescriptor = {
...Object.getOwnPropertyDescriptor(NextComponent, key),
configurable: true
};
// Copy static unless user has redefined it at runtime
if (!wasStaticModifiedByUser(key)) {
Object.defineProperty(ProxyComponent, key, staticDescriptor);
staticDescriptors[key] = staticDescriptor;
}
});
// Remove old static methods and properties
Object.getOwnPropertyNames(ProxyComponent).forEach(key => {
if (RESERVED_STATICS.indexOf(key) > -1) {
return;
}
// Skip statics that exist on the next class
if (NextComponent.hasOwnProperty(key)) {
return;
}
// Skip non-configurable statics
const descriptor = Object.getOwnPropertyDescriptor(ProxyComponent, key);
if (descriptor && !descriptor.configurable) {
return;
}
// Delete static unless user has redefined it at runtime
if (!wasStaticModifiedByUser(key)) {
delete ProxyComponent[key];
delete staticDescriptors[key];
}
});
// Try to infer displayName
ProxyComponent.displayName = NextComponent.displayName || NextComponent.name;
// We might have added new methods that need to be auto-bound
mountedInstances.forEach(bindAutoBindMethods);
mountedInstances.forEach(deleteUnknownAutoBindMethods);
// Let the user take care of redrawing
return mountedInstances;
};
function get() {
return ProxyComponent;
}
function getCurrent() {
return CurrentComponent;
}
update(InitialComponent);
const proxy = { get, update };
addProxy(ProxyComponent, proxy);
Object.defineProperty(proxy, '__getCurrent', {
configurable: false,
writable: false,
enumerable: false,
value: getCurrent
});
return proxy;
}
function createFallback(Component) {
let CurrentComponent = Component;
return {
get() {
return CurrentComponent;
},
update(NextComponent) {
CurrentComponent = NextComponent;
}
};
}
export default function createClassProxy(Component) {
return Component.__proto__ && supportsProtoAssignment() ?
proxyClass(Component) :
createFallback(Component);
}

185
node_modules/react-proxy/src/createPrototypeProxy.js generated vendored Normal file
View File

@@ -0,0 +1,185 @@
import assign from 'lodash/assign';
import difference from 'lodash/difference';
export default function createPrototypeProxy() {
let proxy = {};
let current = null;
let mountedInstances = [];
/**
* Creates a proxied toString() method pointing to the current version's toString().
*/
function proxyToString(name) {
// Wrap to always call the current version
return function toString() {
if (typeof current[name] === 'function') {
return current[name].toString();
} else {
return '<method was deleted>';
}
};
}
/**
* Creates a proxied method that calls the current version, whenever available.
*/
function proxyMethod(name) {
// Wrap to always call the current version
const proxiedMethod = function () {
if (typeof current[name] === 'function') {
return current[name].apply(this, arguments);
}
};
// Copy properties of the original function, if any
assign(proxiedMethod, current[name]);
proxiedMethod.toString = proxyToString(name);
return proxiedMethod;
}
/**
* Augments the original componentDidMount with instance tracking.
*/
function proxiedComponentDidMount() {
mountedInstances.push(this);
if (typeof current.componentDidMount === 'function') {
return current.componentDidMount.apply(this, arguments);
}
}
proxiedComponentDidMount.toString = proxyToString('componentDidMount');
/**
* Augments the original componentWillUnmount with instance tracking.
*/
function proxiedComponentWillUnmount() {
const index = mountedInstances.indexOf(this);
// Unless we're in a weird environment without componentDidMount
if (index !== -1) {
mountedInstances.splice(index, 1);
}
if (typeof current.componentWillUnmount === 'function') {
return current.componentWillUnmount.apply(this, arguments);
}
}
proxiedComponentWillUnmount.toString = proxyToString('componentWillUnmount');
/**
* Defines a property on the proxy.
*/
function defineProxyProperty(name, descriptor) {
Object.defineProperty(proxy, name, descriptor);
}
/**
* Defines a property, attempting to keep the original descriptor configuration.
*/
function defineProxyPropertyWithValue(name, value) {
const {
enumerable = false,
writable = true
} = Object.getOwnPropertyDescriptor(current, name) || {};
defineProxyProperty(name, {
configurable: true,
enumerable,
writable,
value
});
}
/**
* Creates an auto-bind map mimicking the original map, but directed at proxy.
*/
function createAutoBindMap() {
if (!current.__reactAutoBindMap) {
return;
}
let __reactAutoBindMap = {};
for (let name in current.__reactAutoBindMap) {
if (typeof proxy[name] === 'function' && current.__reactAutoBindMap.hasOwnProperty(name)) {
__reactAutoBindMap[name] = proxy[name];
}
}
return __reactAutoBindMap;
}
/**
* Creates an auto-bind map mimicking the original map, but directed at proxy.
*/
function createAutoBindPairs() {
let __reactAutoBindPairs = [];
for (let i = 0; i < current.__reactAutoBindPairs.length; i += 2) {
const name = current.__reactAutoBindPairs[i];
const method = proxy[name];
if (typeof method === 'function') {
__reactAutoBindPairs.push(name, method);
}
}
return __reactAutoBindPairs;
}
/**
* Applies the updated prototype.
*/
function update(next) {
// Save current source of truth
current = next;
// Find changed property names
const currentNames = Object.getOwnPropertyNames(current);
const previousName = Object.getOwnPropertyNames(proxy);
const removedNames = difference(previousName, currentNames);
// Remove properties and methods that are no longer there
removedNames.forEach(name => {
delete proxy[name];
});
// Copy every descriptor
currentNames.forEach(name => {
const descriptor = Object.getOwnPropertyDescriptor(current, name);
if (typeof descriptor.value === 'function') {
// Functions require additional wrapping so they can be bound later
defineProxyPropertyWithValue(name, proxyMethod(name));
} else {
// Other values can be copied directly
defineProxyProperty(name, descriptor);
}
});
// Track mounting and unmounting
defineProxyPropertyWithValue('componentDidMount', proxiedComponentDidMount);
defineProxyPropertyWithValue('componentWillUnmount', proxiedComponentWillUnmount);
if (current.hasOwnProperty('__reactAutoBindMap')) {
defineProxyPropertyWithValue('__reactAutoBindMap', createAutoBindMap());
}
if (current.hasOwnProperty('__reactAutoBindPairs')) {
defineProxyPropertyWithValue('__reactAutoBindPairs', createAutoBindPairs());
}
// Set up the prototype chain
proxy.__proto__ = next;
return mountedInstances;
}
/**
* Returns the up-to-date proxy prototype.
*/
function get() {
return proxy;
}
return {
update,
get
};
};

View File

@@ -0,0 +1,76 @@
function shouldDeleteClassicInstanceMethod(component, name) {
if (component.__reactAutoBindMap && component.__reactAutoBindMap.hasOwnProperty(name)) {
// It's a known autobound function, keep it
return false;
}
if (component.__reactAutoBindPairs && component.__reactAutoBindPairs.indexOf(name) >= 0) {
// It's a known autobound function, keep it
return false;
}
if (component[name].__reactBoundArguments !== null) {
// It's a function bound to specific args, keep it
return false;
}
// It's a cached bound method for a function
// that was deleted by user, so we delete it from component.
return true;
}
function shouldDeleteModernInstanceMethod(component, name) {
const { prototype } = component.constructor;
const prototypeDescriptor = Object.getOwnPropertyDescriptor(prototype, name);
if (!prototypeDescriptor || !prototypeDescriptor.get) {
// This is definitely not an autobinding getter
return false;
}
if (prototypeDescriptor.get().length !== component[name].length) {
// The length doesn't match, bail out
return false;
}
// This seems like a method bound using an autobinding getter on the prototype
// Hopefully we won't run into too many false positives.
return true;
}
function shouldDeleteInstanceMethod(component, name) {
const descriptor = Object.getOwnPropertyDescriptor(component, name);
if (typeof descriptor.value !== 'function') {
// Not a function, or something fancy: bail out
return;
}
if (component.__reactAutoBindMap || component.__reactAutoBindPairs) {
// Classic
return shouldDeleteClassicInstanceMethod(component, name);
} else {
// Modern
return shouldDeleteModernInstanceMethod(component, name);
}
}
/**
* Deletes autobound methods from the instance.
*
* For classic React classes, we only delete the methods that no longer exist in map.
* This means the user actually deleted them in code.
*
* For modern classes, we delete methods that exist on prototype with the same length,
* and which have getters on prototype, but are normal values on the instance.
* This is usually an indication that an autobinding decorator is being used,
* and the getter will re-generate the memoized handler on next access.
*/
export default function deleteUnknownAutoBindMethods(component) {
const names = Object.getOwnPropertyNames(component);
names.forEach(name => {
if (shouldDeleteInstanceMethod(component, name)) {
delete component[name];
}
});
}

14
node_modules/react-proxy/src/index.js generated vendored Normal file
View File

@@ -0,0 +1,14 @@
import supportsProtoAssignment from './supportsProtoAssignment';
if (!supportsProtoAssignment()) {
console.warn(
'This JavaScript environment does not support __proto__. ' +
'This means that react-proxy is unable to proxy React components. ' +
'Features that rely on react-proxy, such as react-transform-hmr, ' +
'will not function as expected.'
);
}
import createProxy from './createClassProxy';
import getForceUpdate from 'react-deep-force-update';
export { createProxy, getForceUpdate };

View File

@@ -0,0 +1,9 @@
const x = {};
const y = { supports: true };
try {
x.__proto__ = y;
} catch (err) {}
export default function supportsProtoAssignment() {
return x.supports || false;
};