Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"The same prototype" #859

Merged
merged 8 commits into from
Feb 18, 2018
Merged

"The same prototype" #859

merged 8 commits into from
Feb 18, 2018

Conversation

theKashey
Copy link
Collaborator

@theKashey theKashey commented Feb 14, 2018

In other words - transfer original class methods into the Proxy prototype, fixes #858

The idea is to leverage a bit side effect caused by React-Hot-Loader's ProxyComponent, to be more concrete - have the same class members list on the top level prototype.
I could not say, that this is super common case, but RHL have to be just a bit more transparent.

https://github.com/uber/react-map-gl/blob/b50de38ab0dfed9e976e1d2e6b0c040629bd82b5/src/utils/autobind.js

export default function autobind(obj) {
  const proto = Object.getPrototypeOf(obj);
  const propNames = Object.getOwnPropertyNames(proto);

  // propNames contains only ProxyComponent methods (render, mount/unmount)
  // should contain methods from base class

  for (const key of propNames) {
    if (typeof obj[key] === 'function') {
      if (!PREDEFINED.find(name => key === name)) {
        obj[key] = obj[key].bind(obj);
      }
    }
  }
}

Related to
visgl/react-map-gl#461

@codecov-io
Copy link

codecov-io commented Feb 14, 2018

Codecov Report

Merging #859 into next will increase coverage by 0.24%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##             next     #859      +/-   ##
==========================================
+ Coverage   86.97%   87.22%   +0.24%     
==========================================
  Files          30       30              
  Lines         622      634      +12     
  Branches      147      149       +2     
==========================================
+ Hits          541      553      +12     
  Misses         65       65              
  Partials       16       16
Impacted Files Coverage Δ
src/proxy/createClassProxy.js 99.01% <100%> (+0.13%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8fa1d42...b93d6e0. Read the comment docs.

@gregberge
Copy link
Collaborator

@theKashey conflict

@theKashey theKashey changed the base branch from no-more-bugs to next February 16, 2018 22:09
@theKashey
Copy link
Collaborator Author

resolved, just "squash" merge to hide unnecessary commits.

@gregberge gregberge merged commit 0b7997f into next Feb 18, 2018
@gregberge gregberge deleted the the-same-prototype branch February 18, 2018 21:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants