Teact: Some improvements
This commit is contained in:
parent
90e56dcdd4
commit
cbd0d47aa5
@ -3,7 +3,7 @@ import { DEBUG } from '../../config';
|
|||||||
type Handler = (e: Event) => void;
|
type Handler = (e: Event) => void;
|
||||||
type DelegationRegistry = Map<Element, Handler>;
|
type DelegationRegistry = Map<Element, Handler>;
|
||||||
|
|
||||||
const NON_BUBBLEABLE_EVENTS = new Set(['scroll', 'mouseenter', 'mouseleave', 'load']);
|
const NON_BUBBLEABLE_EVENTS = new Set(['scroll', 'mouseenter', 'mouseleave', 'load', 'error']);
|
||||||
|
|
||||||
const documentEventCounters: Record<string, number> = {};
|
const documentEventCounters: Record<string, number> = {};
|
||||||
const delegationRegistryByEventType: Record<string, DelegationRegistry> = {};
|
const delegationRegistryByEventType: Record<string, DelegationRegistry> = {};
|
||||||
|
|||||||
@ -46,8 +46,11 @@ const FILTERED_ATTRIBUTES = new Set(['key', 'ref', 'teactFastList', 'teactOrderK
|
|||||||
const HTML_ATTRIBUTES = new Set(['dir', 'role', 'form']);
|
const HTML_ATTRIBUTES = new Set(['dir', 'role', 'form']);
|
||||||
const CONTROLLABLE_TAGS = ['INPUT', 'TEXTAREA', 'SELECT'];
|
const CONTROLLABLE_TAGS = ['INPUT', 'TEXTAREA', 'SELECT'];
|
||||||
const MAPPED_ATTRIBUTES: { [k: string]: string } = {
|
const MAPPED_ATTRIBUTES: { [k: string]: string } = {
|
||||||
autoPlay: 'autoplay',
|
autoCapitalize: 'autocapitalize',
|
||||||
autoComplete: 'autocomplete',
|
autoComplete: 'autocomplete',
|
||||||
|
autoCorrect: 'autocorrect',
|
||||||
|
autoPlay: 'autoplay',
|
||||||
|
spellCheck: 'spellcheck',
|
||||||
};
|
};
|
||||||
const INDEX_KEY_PREFIX = '__indexKey#';
|
const INDEX_KEY_PREFIX = '__indexKey#';
|
||||||
|
|
||||||
|
|||||||
@ -451,11 +451,13 @@ export function renderComponent(componentInstance: ComponentInstance) {
|
|||||||
incrementOverlayCounter(`${componentName} duration`, duration);
|
incrementOverlayCounter(`${componentName} duration`, duration);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, () => {
|
}, {
|
||||||
// eslint-disable-next-line no-console
|
rescue: () => {
|
||||||
console.error(`[Teact] Error while rendering component ${componentInstance.name}`, componentInstance);
|
// eslint-disable-next-line no-console
|
||||||
|
console.error(`[Teact] Error while rendering component ${componentInstance.name}`, componentInstance);
|
||||||
|
|
||||||
newRenderedValue = componentInstance.renderedValue;
|
newRenderedValue = componentInstance.renderedValue;
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (componentInstance.mountState === MountState.Mounted && newRenderedValue === componentInstance.renderedValue) {
|
if (componentInstance.mountState === MountState.Mounted && newRenderedValue === componentInstance.renderedValue) {
|
||||||
@ -766,11 +768,15 @@ function scheduleEffect(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, () => {
|
}, {
|
||||||
// eslint-disable-next-line no-console, max-len
|
rescue: () => {
|
||||||
console.error(`[Teact] Error in effect cleanup at cursor #${cursor} in ${componentInstance.name}`, componentInstance);
|
// eslint-disable-next-line no-console, max-len
|
||||||
}, () => {
|
console.error(`[Teact] Error in effect cleanup at cursor #${cursor} in ${componentInstance.name}`,
|
||||||
byCursor[cursor].cleanup = undefined;
|
componentInstance);
|
||||||
|
},
|
||||||
|
always: () => {
|
||||||
|
byCursor[cursor].cleanup = undefined;
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
cleanupsContainer.set(effectId, runEffectCleanup);
|
cleanupsContainer.set(effectId, runEffectCleanup);
|
||||||
@ -800,9 +806,11 @@ function scheduleEffect(
|
|||||||
console.warn(`[Teact] Slow effect at cursor #${cursor}: ${componentName}, ${Math.round(duration)} ms`);
|
console.warn(`[Teact] Slow effect at cursor #${cursor}: ${componentName}, ${Math.round(duration)} ms`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, () => {
|
}, {
|
||||||
// eslint-disable-next-line no-console
|
rescue: () => {
|
||||||
console.error(`[Teact] Error in effect at cursor #${cursor} in ${componentInstance.name}`, componentInstance);
|
// eslint-disable-next-line no-console
|
||||||
|
console.error(`[Teact] Error in effect at cursor #${cursor} in ${componentInstance.name}`, componentInstance);
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
effectsContainer.set(effectId, runEffect);
|
effectsContainer.set(effectId, runEffect);
|
||||||
|
|||||||
@ -3,20 +3,26 @@ import { handleError } from './handleError';
|
|||||||
|
|
||||||
const SAFE_EXEC_ENABLED = !DEBUG_MORE;
|
const SAFE_EXEC_ENABLED = !DEBUG_MORE;
|
||||||
|
|
||||||
export default function safeExec<F extends AnyFunction>(
|
type SafeExecOptions = {
|
||||||
cb: F,
|
rescue?: (err: Error) => void;
|
||||||
rescue?: (err: Error) => void,
|
always?: NoneToVoidFunction;
|
||||||
always?: NoneToVoidFunction,
|
shouldIgnoreError?: boolean;
|
||||||
): ReturnType<F> | undefined {
|
};
|
||||||
|
|
||||||
|
export default function safeExec<T extends AnyFunction>(cb: T, options?: SafeExecOptions): ReturnType<T> | undefined {
|
||||||
if (!SAFE_EXEC_ENABLED) {
|
if (!SAFE_EXEC_ENABLED) {
|
||||||
return cb();
|
return cb();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { rescue, always, shouldIgnoreError } = options ?? {};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return cb();
|
return cb();
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
rescue?.(err);
|
rescue?.(err);
|
||||||
handleError(err);
|
if (!shouldIgnoreError) {
|
||||||
|
handleError(err);
|
||||||
|
}
|
||||||
return undefined;
|
return undefined;
|
||||||
} finally {
|
} finally {
|
||||||
always?.();
|
always?.();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user