MCPcopy Create free account
hub / github.com/gaearon/react-hot-loader / createClassProxy

Function createClassProxy

src/proxy/createClassProxy.js:100–451  ·  view source on GitHub ↗
(InitialComponent, proxyKey, options = {})

Source from the content-addressed store, hash-verified

98export const forEachKnownClass = cb => knownClassComponents.forEach(cb);
99
100function createClassProxy(InitialComponent, proxyKey, options = {}) {
101 const renderOptions = {
102 ...defaultRenderOptions,
103 ...options,
104 };
105 const proxyConfig = {
106 ...config,
107 ...options.proxy,
108 };
109 // Prevent double wrapping.
110 // Given a proxy class, return the existing proxy managing it.
111 const existingProxy = proxies.get(InitialComponent);
112
113 if (existingProxy) {
114 return existingProxy;
115 }
116
117 let CurrentComponent;
118 let savedDescriptors = {};
119 let injectedMembers = {};
120 let proxyGeneration = 0;
121 let classUpdatePostponed = null;
122 let instancesCount = 0;
123 let isFunctionalComponent = !isReactClass(InitialComponent);
124
125 let lastInstance = null;
126
127 function postConstructionAction() {
128 this[GENERATION] = 0;
129
130 lastInstance = this;
131 // is there is an update pending
132 if (classUpdatePostponed) {
133 const callUpdate = classUpdatePostponed;
134 classUpdatePostponed = null;
135 callUpdate();
136 }
137 // As long we can't override constructor
138 // every class shall evolve from a base class
139 inject(this, proxyGeneration, injectedMembers);
140 }
141
142 function proxiedUpdate() {
143 if (this) {
144 inject(this, proxyGeneration, injectedMembers);
145 }
146 }
147
148 function lifeCycleWrapperFactory(wrapperName, sideEffect = identity) {
149 return copyMethodDescriptors(function wrappedMethod(...rest) {
150 proxiedUpdate.call(this);
151 sideEffect(this);
152 return (
153 !isFunctionalComponent &&
154 CurrentComponent.prototype[wrapperName] &&
155 CurrentComponent.prototype[wrapperName].apply(this, rest)
156 );
157 }, InitialComponent.prototype && InitialComponent.prototype[wrapperName]);

Callers

nothing calls this directly

Calls 8

isReactClassFunction · 0.90
isReactClassInstanceFunction · 0.90
safeDefinePropertyFunction · 0.90
lifeCycleWrapperFactoryFunction · 0.85
defineProxyMethodsFunction · 0.85
transferStaticPropsFunction · 0.85
setSFPFlagFunction · 0.85
updateFunction · 0.85

Tested by

no test coverage detected