Skip to content

Commit 1ac95b3

Browse files
committed
fix: pending Valoscope props now use the lens slots of parent component
Fixes lensAssembly -> slotAssembly
1 parent 5db5260 commit 1ac95b3

File tree

4 files changed

+64
-58
lines changed

4 files changed

+64
-58
lines changed

packages/inspire/ui/UIComponent/LiveProps.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,14 @@ export default class LiveProps extends UIComponent {
139139
_currentSheetContent: ?Object;
140140
_currentSheetObject: ?Object;
141141

142+
readSlotValue (slotName: string, slotSymbol: Symbol, focus: any, onlyIfAble?: boolean) {
143+
// Use the props slots of the parent component because LiveProps
144+
// cannot be explicitly passed any props.
145+
// These slot props should probably be passed to LiveProps inside props, though...
146+
return super.readSlotValue(slotName, slotSymbol, focus, onlyIfAble,
147+
((this.props.parentUIContext || {}).reactComponent || this).props);
148+
}
149+
142150
refreshClassName (focus: any, value: any) {
143151
if ((value == null) || !(value instanceof Vrapper)) return value;
144152
const bindingSlot = `props_className_content`;

packages/inspire/ui/UIComponent/UIComponent.js

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {
2828
} from "./_propsOps";
2929
import {
3030
_renderFocus, _renderFocusAsSequence, _renderFirstAbleDelegate,
31-
_tryRenderLens, _readSlotValue, _tryRenderLensArray, _validateElement,
31+
_tryRenderLens, _tryRenderLensArray, _validateElement,
3232
} from "./_renderOps";
3333
import {
3434
VSSStyleSheetSymbol,
@@ -354,6 +354,43 @@ class UIComponent extends React.Component {
354354
return this.props.elementKey || this.getUIContextValue("key");
355355
}
356356

357+
readSlotValue (slotName: string, slotSymbol: Symbol, focus: any, onlyIfAble?: boolean,
358+
props = this.props):
359+
void | null | string | React.Element<any> | [] | Promise<any> {
360+
if (onlyIfAble) {
361+
const descriptor = this.context.engine.getHostObjectDescriptor(slotSymbol);
362+
if (descriptor
363+
&& (typeof descriptor.isEnabled === "function")
364+
&& !descriptor.isEnabled(focus, this)) {
365+
return undefined;
366+
}
367+
}
368+
let assignee;
369+
try {
370+
assignee = props[slotName];
371+
if (assignee === undefined) {
372+
if (props.hasOwnProperty(slotName)) {
373+
throw new Error(`Render role props.${slotName} is provided but its value is undefined`);
374+
}
375+
assignee = this.getUIContextValue(slotSymbol);
376+
if (assignee === undefined) {
377+
assignee = this.context[slotName];
378+
if (assignee === undefined) return undefined;
379+
} else if (Array.isArray(assignee) && !Object.isFrozen(assignee)) {
380+
assignee = [...assignee]; // the lens chain constantly mutates assignee, return a copy
381+
}
382+
}
383+
return assignee;
384+
} catch (error) {
385+
throw wrapError(error,
386+
`During ${this.debugId()}\n .readSlotValue, with:`,
387+
"\n\tfocus:", focus,
388+
"\n\tslotName:", slotName,
389+
"\n\tslotSymbol:", slotSymbol,
390+
"\n\tassignee:", assignee);
391+
}
392+
}
393+
357394
_subscriptions: Object;
358395
style: Object;
359396

@@ -524,21 +561,14 @@ class UIComponent extends React.Component {
524561

525562
tryRenderLens (lens: any, focus: any = this.tryFocus(), lensName: string, onlyIfAble?: boolean,
526563
onlyOnce?: boolean): void | null | string | React.Element<any> | [] | Promise<any> {
527-
const lensAssembly = this.getUIContextValue(this.getValos().Lens.lensAssembly) || [];
528-
const assemblyLength = lensAssembly.length;
529-
let ret;
530564
try {
531-
lensAssembly.push(lensName);
532-
return (ret = _tryRenderLens(this, lens, focus, lensName, onlyIfAble, onlyOnce));
565+
return _tryRenderLens(this, lens, focus, lensName, onlyIfAble, onlyOnce);
533566
} catch (error) {
534567
throw wrapError(error, `During ${this.debugId()}\n .renderLens, with:`,
535568
"\n\tlensName:", lensName,
536569
"\n\tlens:", lens,
537570
"\n\ttypeof lens:", typeof lens,
538571
"\n\tfocus:", ...dumpObject(focus));
539-
} finally {
540-
if (ret === null) lensAssembly.splice(assemblyLength);
541-
// else lensAssembly[assemblyLength] = { [lensName]: ret };
542572
}
543573
}
544574

@@ -588,10 +618,13 @@ class UIComponent extends React.Component {
588618
const slotName = typeof slot === "string" ? slot : valosLens[slot];
589619
const slotSymbol = typeof slot !== "string" ? slot : valosLens[slot];
590620
const rootSlotName = rootSlotName_ || slotName;
621+
const slotAssembly = this.getUIContextValue(this.getValos().Lens.slotAssembly) || [];
622+
const assemblyLength = slotAssembly.length;
623+
slotAssembly.push(slotName);
591624
try {
592625
if (!slotSymbol) throw new Error(`No valos.Lens slot symbol for '${slotName}'`);
593626
if (!slotName) throw new Error(`No valos.Lens slot name for '${String(slotSymbol)}'`);
594-
slotValue = _readSlotValue(this, slotName, slotSymbol, focus, onlyIfAble);
627+
slotValue = this.readSlotValue(slotName, slotSymbol, focus, onlyIfAble);
595628
ret = slotValue && this.renderLens(
596629
slotValue, focus, `${rootSlotName}-${lensName || ""}`, undefined, onlyOnce);
597630
return ret;
@@ -601,6 +634,8 @@ class UIComponent extends React.Component {
601634
"\n\tfocus:", focus,
602635
"\n\tslot value:", slotValue,
603636
"\n\trootSlotName:", rootSlotName);
637+
} finally {
638+
if (assemblyLength < slotAssembly.length) slotAssembly.splice(assemblyLength);
604639
}
605640
}
606641

@@ -613,7 +648,7 @@ class UIComponent extends React.Component {
613648
this._pendingRenderValue = undefined;
614649
let mainValidationFaults;
615650
let latestRenderedLensSlot;
616-
if (this.state.uiContext) this.setUIContextValue(this.getValos().Lens.lensAssembly, []);
651+
if (this.state.uiContext) this.setUIContextValue(this.getValos().Lens.slotAssembly, []);
617652
try {
618653
const renderNormally = (ret === undefined) && !this._errorObject
619654
&& !_checkForInfiniteRenderRecursion(this);

packages/inspire/ui/UIComponent/_renderOps.js

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -29,43 +29,6 @@ export function _renderFirstAbleDelegate (
2929
return null;
3030
}
3131

32-
export function _readSlotValue (component: UIComponent,
33-
slotName: string, slotSymbol: Symbol, focus: any, onlyIfAble?: boolean):
34-
void | null | string | React.Element<any> | [] | Promise<any> {
35-
if (onlyIfAble) {
36-
const descriptor = component.context.engine.getHostObjectDescriptor(slotSymbol);
37-
if (descriptor
38-
&& (typeof descriptor.isEnabled === "function")
39-
&& !descriptor.isEnabled(focus, component)) {
40-
return undefined;
41-
}
42-
}
43-
let assignee;
44-
try {
45-
assignee = component.props[slotName];
46-
if (typeof assignee === "undefined") {
47-
if (component.props.hasOwnProperty(slotName)) {
48-
throw new Error(`Render role props.${slotName} is provided but its value is undefined`);
49-
}
50-
assignee = component.getUIContextValue(slotSymbol);
51-
if (typeof assignee === "undefined") {
52-
assignee = component.context[slotName];
53-
if (typeof assignee === "undefined") return undefined;
54-
} else if (Array.isArray(assignee) && !Object.isFrozen(assignee)) {
55-
assignee = [...assignee]; // the lens chain constantly mutates assignee, return a copy
56-
}
57-
}
58-
return assignee;
59-
} catch (error) {
60-
throw wrapError(error,
61-
`During ${component.debugId()}\n ._readSlotValue, with:`,
62-
"\n\tfocus:", focus,
63-
"\n\tslotName:", slotName,
64-
"\n\tslotSymbol:", slotSymbol,
65-
"\n\tassignee:", assignee);
66-
}
67-
}
68-
6932
export function _renderFocusAsSequence (component: UIComponent,
7033
foci: any[], EntryElement: Object, entryProps: Object,
7134
keyFromFocus?: (focus: any, index: number) => string,
@@ -186,7 +149,7 @@ export function _tryRenderLens (component: UIComponent, lens: any, focus: any,
186149
} else {
187150
const valos = component.getValos();
188151
subLensName = `delegate-lens-${lensName}`;
189-
ret = _readSlotValue(component, "delegatePropertyLens",
152+
ret = component.readSlotValue("delegatePropertyLens",
190153
valos.Lens.delegatePropertyLens, lens, true)(lens, component, lensName);
191154
if ((ret == null) || ((ret.delegate || [])[0] === valos.Lens.notLensResourceLens)) {
192155
return component.renderSlotAsLens("notLensResourceLens", lens, undefined, subLensName);

packages/inspire/valosheath/valos/injectLensObjects.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,14 @@ export default function injectLensObjects (valos: Object, rootScope: Object,
9999

100100
// Primitive lenses
101101

102-
const lensAssembly = createSlotSymbol("lensAssembly", () => ({
102+
const slotAssembly = createSlotSymbol("slotAssembly", () => ({
103103
type: "string[]",
104104
description: `Slot which contains the lens slot assembly that is used by the component.`,
105105
}));
106106

107107
const niceActiveSlotNames = valos.Lens.instrument(
108-
lensAssembly,
109-
slotNames => slotNames.slice(0, -1).reverse().join(" <- "));
108+
slotAssembly,
109+
slotNames => slotNames.slice(0, -1).reverse().join(" <| "));
110110

111111
const componentChildrenLens = createSlotSymbol("componentChildrenLens", () => ({
112112
type: "Lens",
@@ -850,12 +850,12 @@ export default function injectLensObjects (valos: Object, rootScope: Object,
850850
rootValue: ({ delegate: [
851851
loadingLens,
852852
<div {..._lensMessageLoadingProps}>
853-
<div {..._message}>Waiting for a pending dependency Promise to resolve.</div>
854-
<div {..._parameter}>
855-
<span {..._key}>Dependency:</span>
856-
<span {..._value}>{focusDetailLens}</span>
857-
</div>
858-
{commonMessageRows}
853+
<div {..._message}>Waiting for a pending dependency Promise to resolve.</div>
854+
<div {..._parameter}>
855+
<span {..._key}>Dependency:</span>
856+
<span {..._value}>{focusDetailLens}</span>
857+
</div>
858+
{commonMessageRows}
859859
</div>
860860
] }),
861861
}));

0 commit comments

Comments
 (0)