Skip to content

Commit

Permalink
Migrate ancestor component to a new _ancestorComponent property (and …
Browse files Browse the repository at this point in the history
…update minification to rename this new property to __a)
  • Loading branch information
rpetrich committed Sep 12, 2017
1 parent f3afbeb commit b616cc8
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 8 deletions.
1 change: 1 addition & 0 deletions config/properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"$prevProps": "__p",
"$prevState": "__s",
"$_parentComponent": "__u",
"$_ancestorComponent": "__a",
"$_componentConstructor": "_componentConstructor",
"$__html": "__html",
"$_component": "_component",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"transpile:esm": "rollup -c config/rollup.config.esm.js",
"transpile:debug": "babel debug/ -o debug.js -s",
"transpile": "npm-run-all transpile:main transpile:esm transpile:devtools transpile:debug",
"optimize": "uglifyjs dist/preact.dev.js -c conditionals=false,sequences=false,loops=false,join_vars=false,collapse_vars=false --pure-funcs=Object.defineProperty --mangle-props --mangle-regex=\"/^(_|normalizedNodeName|nextBase|prev[CPS]|_parentC)/\" --name-cache config/properties.json -b width=120,quote_style=3 -o dist/preact.js -p relative --in-source-map dist/preact.dev.js.map --source-map dist/preact.js.map",
"optimize": "uglifyjs dist/preact.dev.js -c conditionals=false,sequences=false,loops=false,join_vars=false,collapse_vars=false --pure-funcs=Object.defineProperty --mangle-props --mangle-regex=\"/^(_|normalizedNodeName|nextBase|prev[CPS]|_parentC|_ancestorC)/\" --name-cache config/properties.json -b width=120,quote_style=3 -o dist/preact.js -p relative --in-source-map dist/preact.dev.js.map --source-map dist/preact.js.map",
"minify": "uglifyjs dist/preact.js -c collapse_vars,evaluate,screw_ie8,unsafe,loops=false,keep_fargs=false,pure_getters,unused,dead_code -m -o dist/preact.min.js -p relative --in-source-map dist/preact.js.map --source-map dist/preact.min.js.map",
"strip:main": "jscodeshift --run-in-band -s -t config/codemod-strip-tdz.js dist/preact.dev.js && jscodeshift --run-in-band -s -t config/codemod-const.js dist/preact.dev.js && jscodeshift --run-in-band -s -t config/codemod-let-name.js dist/preact.dev.js",
"strip:esm": "jscodeshift --run-in-band -s -t config/codemod-strip-tdz.js dist/preact.esm.js && jscodeshift --run-in-band -s -t config/codemod-const.js dist/preact.esm.js && jscodeshift --run-in-band -s -t config/codemod-let-name.js dist/preact.esm.js",
Expand Down
4 changes: 2 additions & 2 deletions src/vdom/component-recycler.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function collectComponent(component) {


/** Create a component. Normalizes differences between PFC's and classful Components. */
export function createComponent(Ctor, props, context, parentComponent) {
export function createComponent(Ctor, props, context, ancestorComponent) {
let list = components[Ctor.name],
inst;

Expand All @@ -28,7 +28,7 @@ export function createComponent(Ctor, props, context, parentComponent) {
inst.constructor = Ctor;
inst.render = doRender;
}
inst._parentComponent = parentComponent;
inst._ancestorComponent = ancestorComponent;

if (list) {
for (let i=list.length; i--; ) {
Expand Down
9 changes: 5 additions & 4 deletions src/vdom/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export function setComponentProps(component, props, opts, context, mountAll) {
}

export function catchErrorInComponent(error, component) {
for (; component; component = component._parentComponent) {
for (; component; component = component._ancestorComponent) {
if (component.componentDidCatch) {
try {
return component.componentDidCatch(error);
Expand Down Expand Up @@ -132,6 +132,7 @@ export function renderComponent(component, opts, mountAll, isChild) {

component._component = inst = createComponent(childComponent, childProps, context, component);
inst.nextBase = inst.nextBase || nextBase;
inst._parentComponent = component;
setComponentProps(inst, childProps, NO_RENDER, context, false);
renderComponent(inst, SYNC_RENDER, mountAll, true);
}
Expand Down Expand Up @@ -191,7 +192,7 @@ export function renderComponent(component, opts, mountAll, isChild) {
try {
component.componentDidUpdate(previousProps, previousState, previousContext);
} catch (e) {
catchErrorInComponent(e, component._parentComponent);
catchErrorInComponent(e, component._ancestorComponent);
}
}
if (options.afterUpdate) options.afterUpdate(component);
Expand All @@ -212,7 +213,7 @@ export function renderComponent(component, opts, mountAll, isChild) {
* @returns {Element} dom The created/mutated element
* @private
*/
export function buildComponentFromVNode(dom, vnode, context, mountAll, parentComponent) {
export function buildComponentFromVNode(dom, vnode, context, mountAll, ancestorComponent) {
let c = dom && dom._component,
originalComponent = c,
oldDom = dom,
Expand All @@ -233,7 +234,7 @@ export function buildComponentFromVNode(dom, vnode, context, mountAll, parentCom
dom = oldDom = null;
}

c = createComponent(vnode.nodeName, props, context, parentComponent);
c = createComponent(vnode.nodeName, props, context, ancestorComponent);
if (dom && !c.nextBase) {
c.nextBase = dom;
// passing dom/oldDom as nextBase will recycle it if unused, so bypass recycling on L229:
Expand Down
2 changes: 1 addition & 1 deletion src/vdom/diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function flushMounts() {
try {
c.componentDidMount();
} catch (e) {
catchErrorInComponent(e, c._parentComponent);
catchErrorInComponent(e, c._ancestorComponent);
}
}
}
Expand Down

0 comments on commit b616cc8

Please sign in to comment.