Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
"webpack": "1.4.8"
},
"dependencies": {
"lodash": "^4.6.1",
"react-deep-force-update": "^1.0.0"
}
}
5 changes: 2 additions & 3 deletions src/createClassProxy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import find from 'lodash/find';
import createPrototypeProxy from './createPrototypeProxy';
import bindAutoBindMethods from './bindAutoBindMethods';
import deleteUnknownAutoBindMethods from './deleteUnknownAutoBindMethods';
Expand Down Expand Up @@ -32,14 +31,14 @@ function isEqualDescriptor(a, b) {
// https://github.com/gaearon/react-proxy/issues/50#issuecomment-192928066
let allProxies = [];
function findProxy(Component) {
const pair = find(allProxies, ([key]) => key === Component);
const pair = allProxies.find(([key]) => key === Component);
return pair ? pair[1] : null;
}
function addProxy(Component, proxy) {
allProxies.push([Component, proxy]);
}

export default function proxyClass(InitialComponent) {
export function proxyClass(InitialComponent) {
// Prevent double wrapping.
// Given a proxy class, return the existing proxy managing it.
var existingProxy = findProxy(InitialComponent);
Expand Down
20 changes: 15 additions & 5 deletions src/createPrototypeProxy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import assign from 'lodash/assign';
import difference from 'lodash/difference';

export default function createPrototypeProxy() {
let proxy = {};
let current = null;
Expand Down Expand Up @@ -32,7 +29,7 @@ export default function createPrototypeProxy() {
};

// Copy properties of the original function, if any
assign(proxiedMethod, current[name]);
Object.assign(proxiedMethod, current[name]);
proxiedMethod.toString = proxyToString(name);

return proxiedMethod;
Expand Down Expand Up @@ -134,7 +131,20 @@ export default function createPrototypeProxy() {
// Find changed property names
const currentNames = Object.getOwnPropertyNames(current);
const previousName = Object.getOwnPropertyNames(proxy);
const removedNames = difference(previousName, currentNames);

// Map the property names as keys in an object to get constant time access
// when calculating the removed properties.
const currentNamesObject = currentNames.reduce(
(acc, property) => {
acc[property] = true;
return acc;
},
Object.create(null),
);

const removedNames = previousName.filter(
property => !currentNames[property],
);

// Remove properties and methods that are no longer there
removedNames.forEach(name => {
Expand Down