Skip to content

Commit

Permalink
chore: init. wip
Browse files Browse the repository at this point in the history
  • Loading branch information
John Jenkins committed Feb 19, 2025
1 parent eafe1f9 commit b5db37a
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 85 deletions.
10 changes: 0 additions & 10 deletions src/app-data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,10 @@ import type { BuildConditionals } from '@stencil/core/internal';
*/
export const BUILD: BuildConditionals = {
allRenderFn: false,
cmpDidLoad: true,
cmpDidUnload: false,
cmpDidUpdate: true,
cmpDidRender: true,
cmpWillLoad: true,
cmpWillUpdate: true,
cmpWillRender: true,
connectedCallback: true,
disconnectedCallback: true,
element: true,
event: true,
hasRenderFn: true,
lifecycle: true,
hostListener: true,
hostListenerTargetWindow: true,
hostListenerTargetDocument: true,
Expand Down Expand Up @@ -101,7 +92,6 @@ export const BUILD: BuildConditionals = {
propNumber: true,
propString: true,
constructableCSS: true,
cmpShouldUpdate: true,
devTools: false,
shadowDelegatesFocus: true,
initializeNextTick: false,
Expand Down
14 changes: 2 additions & 12 deletions src/compiler/app-core/app-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,12 @@ export const getBuildFeatures = (cmps: ComponentCompilerMeta[]): BuildFeatures =
const slotRelocation = cmps.some((c) => c.encapsulation !== 'shadow' && c.htmlTagNames.includes('slot'));
const f: BuildFeatures = {
allRenderFn: cmps.every((c) => c.hasRenderFn),
cmpDidLoad: cmps.some((c) => c.hasComponentDidLoadFn),
cmpShouldUpdate: cmps.some((c) => c.hasComponentShouldUpdateFn),
cmpDidUnload: cmps.some((c) => c.hasComponentDidUnloadFn),
cmpDidUpdate: cmps.some((c) => c.hasComponentDidUpdateFn),
cmpDidRender: cmps.some((c) => c.hasComponentDidRenderFn),
cmpWillLoad: cmps.some((c) => c.hasComponentWillLoadFn),
cmpWillUpdate: cmps.some((c) => c.hasComponentWillUpdateFn),
cmpWillRender: cmps.some((c) => c.hasComponentWillRenderFn),
formAssociated: cmps.some((c) => c.formAssociated),

connectedCallback: cmps.some((c) => c.hasConnectedCallbackFn),
disconnectedCallback: cmps.some((c) => c.hasDisconnectedCallbackFn),
element: cmps.some((c) => c.hasElement),
event: cmps.some((c) => c.hasEvent),
hasRenderFn: cmps.some((c) => c.hasRenderFn),
lifecycle: cmps.some((c) => c.hasLifecycle),
asyncLoading: false,
hostListener: cmps.some((c) => c.hasListener),
hostListenerTargetWindow: cmps.some((c) => c.hasListenerTargetWindow),
Expand Down Expand Up @@ -81,7 +71,7 @@ export const getBuildFeatures = (cmps: ComponentCompilerMeta[]): BuildFeatures =
watchCallback: cmps.some((c) => c.hasWatchCallback),
taskQueue: true,
};
f.asyncLoading = f.cmpWillUpdate || f.cmpWillLoad || f.cmpWillRender;
f.asyncLoading = true;
f.vdomAttribute = f.vdomAttribute || f.reflect;
f.vdomPropOrAttr = f.vdomPropOrAttr || f.reflect;

Expand Down Expand Up @@ -160,7 +150,7 @@ export const updateBuildConditionals = (config: ValidatedConfig, b: BuildConditi
!config._isTesting
);
b.updatable = b.updatable || b.hydrateClientSide || b.hotModuleReplacement;
b.member = b.member || b.updatable || b.mode || b.lifecycle;
b.member = b.member || b.updatable || b.mode;
b.constructableCSS = !b.hotModuleReplacement || !!config._isTesting;
b.asyncLoading = !!(b.asyncLoading || b.lazyLoad || b.taskQueue || b.initializeNextTick);
b.cssAnnotations = true;
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/transformers/component-build-conditionals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ export const setComponentBuildConditionals = (cmpMeta: d.ComponentCompilerMeta)
cmpMeta.hasComponentWillRenderFn ||
cmpMeta.hasComponentDidRenderFn;
cmpMeta.isPlain =
!cmpMeta.hasMember && !cmpMeta.hasStyle && !cmpMeta.hasLifecycle && !cmpMeta.hasListener && !cmpMeta.hasVdomRender;
!cmpMeta.hasMember && !cmpMeta.hasStyle && !cmpMeta.hasListener && !cmpMeta.hasVdomRender;
};
10 changes: 0 additions & 10 deletions src/declarations/stencil-private.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,7 @@ export interface BuildFeatures {
modernPropertyDecls: boolean;

// lifecycle events
lifecycle: boolean;
cmpDidLoad: boolean;
cmpShouldUpdate: boolean;
cmpWillLoad: boolean;
cmpDidUpdate: boolean;
cmpWillUpdate: boolean;
cmpWillRender: boolean;
cmpDidRender: boolean;
cmpDidUnload: boolean;
connectedCallback: boolean;
disconnectedCallback: boolean;
asyncLoading: boolean;

// attr
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/bootstrap-custom-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ export const proxyCustomElement = (Cstr: any, compactMeta: d.ComponentRuntimeMet
}

connectedCallback(this);
if (BUILD.connectedCallback && originalConnectedCallback) {
if (originalConnectedCallback) {
originalConnectedCallback.call(this);
}
},
disconnectedCallback() {
disconnectedCallback(this);
if (BUILD.disconnectedCallback && originalDisconnectedCallback) {
if (originalDisconnectedCallback) {
originalDisconnectedCallback.call(this);
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/disconnected-callback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { rootAppliedStyles } from './styles';
import { safeCall } from './update-component';

const disconnectInstance = (instance: any, elm?: d.HostElement) => {
if (BUILD.lazyLoad && BUILD.disconnectedCallback) {
if (BUILD.lazyLoad) {
safeCall(instance, 'disconnectedCallback', undefined, elm || instance);
}
if (BUILD.cmpDidUnload) {
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/initialize-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export const initializeComponent = async (
};

export const fireConnectedCallback = (instance: any, elm?: HTMLElement) => {
if (BUILD.lazyLoad && BUILD.connectedCallback) {
if (BUILD.lazyLoad) {
safeCall(instance, 'connectedCallback', undefined, elm);
}
};
2 changes: 1 addition & 1 deletion src/runtime/set-value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export const setValue = (ref: d.RuntimeRef, propName: string, newVal: any, cmpMe
BUILD.updatable &&
(flags & (HOST_FLAGS.hasRendered | HOST_FLAGS.isQueuedForUpdate)) === HOST_FLAGS.hasRendered
) {
if (BUILD.cmpShouldUpdate && instance.componentShouldUpdate) {
if (instance.componentShouldUpdate) {
if (instance.componentShouldUpdate(newVal, oldVal, propName) === false) {
return;
}
Expand Down
82 changes: 35 additions & 47 deletions src/runtime/update-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,31 +97,25 @@ const dispatchHooks = (hostRef: d.HostRef, isInitialLoad: boolean): Promise<void
}
}
emitLifecycleEvent(elm, 'componentWillLoad');
if (BUILD.cmpWillLoad) {
// If `componentWillLoad` returns a `Promise` then we want to wait on
// whatever's going on in that `Promise` before we launch into
// rendering the component, doing other lifecycle stuff, etc. So
// in that case we assign the returned promise to the variable we
// declared above to hold a possible 'queueing' Promise
maybePromise = safeCall(instance, 'componentWillLoad', undefined, elm);
}
// If `componentWillLoad` returns a `Promise` then we want to wait on
// whatever's going on in that `Promise` before we launch into
// rendering the component, doing other lifecycle stuff, etc. So
// in that case we assign the returned promise to the variable we
// declared above to hold a possible 'queueing' Promise
maybePromise = safeCall(instance, 'componentWillLoad', undefined, elm);
} else {
emitLifecycleEvent(elm, 'componentWillUpdate');

if (BUILD.cmpWillUpdate) {
// Like `componentWillLoad` above, we allow Stencil component
// authors to return a `Promise` from this lifecycle callback, and
// we specify that our runtime will wait for that `Promise` to
// resolve before the component re-renders. So if the method
// returns a `Promise` we need to keep it around!
maybePromise = safeCall(instance, 'componentWillUpdate', undefined, elm);
}
// Like `componentWillLoad` above, we allow Stencil component
// authors to return a `Promise` from this lifecycle callback, and
// we specify that our runtime will wait for that `Promise` to
// resolve before the component re-renders. So if the method
// returns a `Promise` we need to keep it around!
maybePromise = safeCall(instance, 'componentWillUpdate', undefined, elm);
}

emitLifecycleEvent(elm, 'componentWillRender');
if (BUILD.cmpWillRender) {
maybePromise = enqueue(maybePromise, () => safeCall(instance, 'componentWillRender', undefined, elm));
}
maybePromise = enqueue(maybePromise, () => safeCall(instance, 'componentWillRender', undefined, elm));

endSchedule();

Expand Down Expand Up @@ -322,14 +316,12 @@ export const postUpdateComponent = (hostRef: d.HostRef) => {
const instance = BUILD.lazyLoad ? hostRef.$lazyInstance$ : (elm as any);
const ancestorComponent = hostRef.$ancestorComponent$;

if (BUILD.cmpDidRender) {
if (BUILD.isDev) {
hostRef.$flags$ |= HOST_FLAGS.devOnRender;
}
safeCall(instance, 'componentDidRender', undefined, elm);
if (BUILD.isDev) {
hostRef.$flags$ &= ~HOST_FLAGS.devOnRender;
}
if (BUILD.isDev) {
hostRef.$flags$ |= HOST_FLAGS.devOnRender;
}
safeCall(instance, 'componentDidRender', undefined, elm);
if (BUILD.isDev) {
hostRef.$flags$ &= ~HOST_FLAGS.devOnRender;
}
emitLifecycleEvent(elm, 'componentDidRender');

Expand All @@ -341,14 +333,12 @@ export const postUpdateComponent = (hostRef: d.HostRef) => {
addHydratedFlag(elm);
}

if (BUILD.cmpDidLoad) {
if (BUILD.isDev) {
hostRef.$flags$ |= HOST_FLAGS.devOnDidLoad;
}
safeCall(instance, 'componentDidLoad', undefined, elm);
if (BUILD.isDev) {
hostRef.$flags$ &= ~HOST_FLAGS.devOnDidLoad;
}
if (BUILD.isDev) {
hostRef.$flags$ |= HOST_FLAGS.devOnDidLoad;
}
safeCall(instance, 'componentDidLoad', undefined, elm);
if (BUILD.isDev) {
hostRef.$flags$ &= ~HOST_FLAGS.devOnDidLoad;
}

emitLifecycleEvent(elm, 'componentDidLoad');
Expand All @@ -361,18 +351,16 @@ export const postUpdateComponent = (hostRef: d.HostRef) => {
}
}
} else {
if (BUILD.cmpDidUpdate) {
// we've already loaded this component
// fire off the user's componentDidUpdate method (if one was provided)
// componentDidUpdate runs AFTER render() has been called
// and all child components have finished updating
if (BUILD.isDev) {
hostRef.$flags$ |= HOST_FLAGS.devOnRender;
}
safeCall(instance, 'componentDidUpdate', undefined, elm);
if (BUILD.isDev) {
hostRef.$flags$ &= ~HOST_FLAGS.devOnRender;
}
// we've already loaded this component
// fire off the user's componentDidUpdate method (if one was provided)
// componentDidUpdate runs AFTER render() has been called
// and all child components have finished updating
if (BUILD.isDev) {
hostRef.$flags$ |= HOST_FLAGS.devOnRender;
}
safeCall(instance, 'componentDidUpdate', undefined, elm);
if (BUILD.isDev) {
hostRef.$flags$ &= ~HOST_FLAGS.devOnRender;
}
emitLifecycleEvent(elm, 'componentDidUpdate');
endPostUpdate();
Expand Down

0 comments on commit b5db37a

Please sign in to comment.