First commit
This commit is contained in:
104
hGameTest/node_modules/react-proxy/README.md
generated
vendored
Normal file
104
hGameTest/node_modules/react-proxy/README.md
generated
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
# React Proxy [](https://travis-ci.org/gaearon/react-proxy) [](https://www.npmjs.com/package/react-proxy)
|
||||
|
||||
A generic React component proxy useful for hot reloading.
|
||||
|
||||
## Requirements
|
||||
|
||||
* React 0.14+
|
||||
|
||||
## Usage
|
||||
|
||||
Intended to be used from hot reloading tools like React Hot Loader.
|
||||
If you’re an application developer, it’s unlikely you’ll want to use it directly.
|
||||
|
||||
You will need something like [react-deep-force-update](https://github.com/gaearon/react-deep-force-update) to re-render the component tree after applying the update.
|
||||
|
||||
```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 React from 'react';
|
||||
import { render } from 'react-dom';
|
||||
import createProxy from 'react-proxy';
|
||||
import deepForceUpdate from 'react-deep-force-update';
|
||||
|
||||
// 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).
|
||||
const rootInstance = 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.
|
||||
proxy.update(ComponentVersion2);
|
||||
|
||||
// Force-update the whole React component tree.
|
||||
// Until React provides an official DevTools API to do this,
|
||||
// you should keep the reference to the root instance(s).
|
||||
deepForceUpdate(rootInstance);
|
||||
```
|
||||
|
||||
## Features
|
||||
|
||||
* Supports both classic (`React.createClass()`) and modern (ES6 classes) style
|
||||
* Supports inherited and base classes (although you shouldn’t 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
|
||||
4843
hGameTest/node_modules/react-proxy/dist/ReactProxy.js
generated
vendored
Normal file
4843
hGameTest/node_modules/react-proxy/dist/ReactProxy.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
93
hGameTest/node_modules/react-proxy/modules/bindAutoBindMethods.js
generated
vendored
Normal file
93
hGameTest/node_modules/react-proxy/modules/bindAutoBindMethods.js
generated
vendored
Normal 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);
|
||||
}
|
||||
}
|
||||
246
hGameTest/node_modules/react-proxy/modules/createClassProxy.js
generated
vendored
Normal file
246
hGameTest/node_modules/react-proxy/modules/createClassProxy.js
generated
vendored
Normal file
@@ -0,0 +1,246 @@
|
||||
'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 = 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 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);
|
||||
};
|
||||
}
|
||||
|
||||
// Proxy toString() to the current constructor
|
||||
ProxyComponent.toString = function toString() {
|
||||
return CurrentComponent.toString();
|
||||
};
|
||||
|
||||
var prototypeProxy = undefined;
|
||||
if (InitialComponent.prototype && InitialComponent.prototype.isReactComponent) {
|
||||
// Point proxy constructor to the proxy prototype
|
||||
prototypeProxy = (0, _createPrototypeProxy2.default)();
|
||||
ProxyComponent.prototype = prototypeProxy.get();
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
// Try to infer displayName
|
||||
ProxyComponent.displayName = NextComponent.displayName || NextComponent.name;
|
||||
|
||||
// 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];
|
||||
}
|
||||
});
|
||||
|
||||
if (prototypeProxy) {
|
||||
// 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;
|
||||
|
||||
// We might have added new methods that need to be auto-bound
|
||||
mountedInstances.forEach(_bindAutoBindMethods2.default);
|
||||
mountedInstances.forEach(_deleteUnknownAutoBindMethods2.default);
|
||||
}
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
||||
202
hGameTest/node_modules/react-proxy/modules/createPrototypeProxy.js
generated
vendored
Normal file
202
hGameTest/node_modules/react-proxy/modules/createPrototypeProxy.js
generated
vendored
Normal 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
|
||||
};
|
||||
};
|
||||
83
hGameTest/node_modules/react-proxy/modules/deleteUnknownAutoBindMethods.js
generated
vendored
Normal file
83
hGameTest/node_modules/react-proxy/modules/deleteUnknownAutoBindMethods.js
generated
vendored
Normal 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];
|
||||
}
|
||||
});
|
||||
}
|
||||
21
hGameTest/node_modules/react-proxy/modules/index.js
generated
vendored
Normal file
21
hGameTest/node_modules/react-proxy/modules/index.js
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _supportsProtoAssignment = require('./supportsProtoAssignment');
|
||||
|
||||
var _supportsProtoAssignment2 = _interopRequireDefault(_supportsProtoAssignment);
|
||||
|
||||
var _createClassProxy = require('./createClassProxy');
|
||||
|
||||
var _createClassProxy2 = _interopRequireDefault(_createClassProxy);
|
||||
|
||||
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.default = _createClassProxy2.default;
|
||||
15
hGameTest/node_modules/react-proxy/modules/supportsProtoAssignment.js
generated
vendored
Normal file
15
hGameTest/node_modules/react-proxy/modules/supportsProtoAssignment.js
generated
vendored
Normal 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;
|
||||
};
|
||||
100
hGameTest/node_modules/react-proxy/package.json
generated
vendored
Normal file
100
hGameTest/node_modules/react-proxy/package.json
generated
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
{
|
||||
"_from": "react-proxy@^2.0.8",
|
||||
"_id": "react-proxy@2.0.8",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-dq54yb5OVNQJz+x7t9UT7H8bKEw=",
|
||||
"_location": "/react-proxy",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "react-proxy@^2.0.8",
|
||||
"name": "react-proxy",
|
||||
"escapedName": "react-proxy",
|
||||
"rawSpec": "^2.0.8",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^2.0.8"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/haxe-modular"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/react-proxy/-/react-proxy-2.0.8.tgz",
|
||||
"_shasum": "76ae78c9be4e54d409cfec7bb7d513ec7f1b284c",
|
||||
"_spec": "react-proxy@^2.0.8",
|
||||
"_where": "/home/andreas/Documents/Projects/haxe/openfl/nigger/node_modules/haxe-modular",
|
||||
"author": {
|
||||
"name": "Dan Abramov",
|
||||
"email": "dan.abramov@me.com",
|
||||
"url": "http://github.com/gaearon"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/gaearon/react-proxy/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"lodash": "^4.6.1"
|
||||
},
|
||||
"deprecated": false,
|
||||
"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.14.0",
|
||||
"react-addons-test-utils": "^0.14.0",
|
||||
"rimraf": "^2.4.2",
|
||||
"webpack": "1.4.8"
|
||||
},
|
||||
"files": [
|
||||
"dist",
|
||||
"modules",
|
||||
"src"
|
||||
],
|
||||
"homepage": "https://github.com/gaearon/react-proxy",
|
||||
"license": "MIT",
|
||||
"main": "modules/index.js",
|
||||
"name": "react-proxy",
|
||||
"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": "2.0.8"
|
||||
}
|
||||
103
hGameTest/node_modules/react-proxy/src/bindAutoBindMethods.js
generated
vendored
Normal file
103
hGameTest/node_modules/react-proxy/src/bindAutoBindMethods.js
generated
vendored
Normal 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
|
||||
);
|
||||
}
|
||||
}
|
||||
219
hGameTest/node_modules/react-proxy/src/createClassProxy.js
generated
vendored
Normal file
219
hGameTest/node_modules/react-proxy/src/createClassProxy.js
generated
vendored
Normal file
@@ -0,0 +1,219 @@
|
||||
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]);
|
||||
}
|
||||
|
||||
function proxyClass(InitialComponent) {
|
||||
// Prevent double wrapping.
|
||||
// Given a proxy class, return the existing proxy managing it.
|
||||
var existingProxy = findProxy(InitialComponent);
|
||||
if (existingProxy) {
|
||||
return existingProxy;
|
||||
}
|
||||
|
||||
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);
|
||||
};
|
||||
}
|
||||
|
||||
// Proxy toString() to the current constructor
|
||||
ProxyComponent.toString = function toString() {
|
||||
return CurrentComponent.toString();
|
||||
};
|
||||
|
||||
let prototypeProxy;
|
||||
if (InitialComponent.prototype && InitialComponent.prototype.isReactComponent) {
|
||||
// Point proxy constructor to the proxy prototype
|
||||
prototypeProxy = createPrototypeProxy();
|
||||
ProxyComponent.prototype = prototypeProxy.get();
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
// Try to infer displayName
|
||||
ProxyComponent.displayName = NextComponent.displayName || NextComponent.name;
|
||||
|
||||
// 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];
|
||||
}
|
||||
});
|
||||
|
||||
if (prototypeProxy) {
|
||||
// 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;
|
||||
|
||||
// We might have added new methods that need to be auto-bound
|
||||
mountedInstances.forEach(bindAutoBindMethods);
|
||||
mountedInstances.forEach(deleteUnknownAutoBindMethods);
|
||||
}
|
||||
};
|
||||
|
||||
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
hGameTest/node_modules/react-proxy/src/createPrototypeProxy.js
generated
vendored
Normal file
185
hGameTest/node_modules/react-proxy/src/createPrototypeProxy.js
generated
vendored
Normal 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
|
||||
};
|
||||
};
|
||||
76
hGameTest/node_modules/react-proxy/src/deleteUnknownAutoBindMethods.js
generated
vendored
Normal file
76
hGameTest/node_modules/react-proxy/src/deleteUnknownAutoBindMethods.js
generated
vendored
Normal 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];
|
||||
}
|
||||
});
|
||||
}
|
||||
13
hGameTest/node_modules/react-proxy/src/index.js
generated
vendored
Normal file
13
hGameTest/node_modules/react-proxy/src/index.js
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
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 createClassProxy from './createClassProxy';
|
||||
export default createClassProxy;
|
||||
9
hGameTest/node_modules/react-proxy/src/supportsProtoAssignment.js
generated
vendored
Normal file
9
hGameTest/node_modules/react-proxy/src/supportsProtoAssignment.js
generated
vendored
Normal 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;
|
||||
};
|
||||
Reference in New Issue
Block a user