Skip to content

Commit

Permalink
refactor(runtime-vapor): remove optional chaining syntax (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
LittleSound committed May 12, 2024
1 parent b3cb392 commit 9346f88
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/runtime-vapor/src/component.ts
Expand Up @@ -249,7 +249,7 @@ export const setCurrentInstance = (instance: ComponentInternalInstance) => {
}

export const unsetCurrentInstance = () => {
currentInstance?.scope.off()
currentInstance && currentInstance.scope.off()
currentInstance = null
}

Expand Down
4 changes: 3 additions & 1 deletion packages/runtime-vapor/src/componentSlots.ts
Expand Up @@ -86,7 +86,9 @@ export function initSlots(
for (const key in dynamicSlotKeys) {
if (
!_dynamicSlots.some(slot =>
isArray(slot) ? slot.some(s => s.name === key) : slot?.name === key,
slot && isArray(slot)
? slot.some(s => s.name === key)
: slot.name === key,
)
) {
delete slots[key]
Expand Down
8 changes: 4 additions & 4 deletions packages/runtime-vapor/src/renderEffect.ts
Expand Up @@ -25,7 +25,7 @@ export function renderEffect(cb: () => void) {
return
}

if (instance?.isMounted && !instance.isUpdating) {
if (instance && instance.isMounted && !instance.isUpdating) {
instance.isUpdating = true

const { bu, u, dirs } = instance
Expand Down Expand Up @@ -76,11 +76,11 @@ export function renderEffect(cb: () => void) {
if (instance) job.id = instance.uid
queueJob(job)
}
if (__DEV__) {
effect.onTrack = instance?.rtc
if (__DEV__ && instance) {
effect.onTrack = instance.rtc
? e => invokeArrayFns(instance.rtc!, e)
: void 0
effect.onTrigger = instance?.rtg
effect.onTrigger = instance.rtg
? e => invokeArrayFns(instance.rtg!, e)
: void 0
}
Expand Down
3 changes: 2 additions & 1 deletion packages/runtime-vapor/src/scheduler.ts
Expand Up @@ -33,13 +33,14 @@ const resolvedPromise = /*#__PURE__*/ Promise.resolve() as Promise<any>
let currentFlushPromise: Promise<void> | null = null

export function queueJob(job: SchedulerJob) {
let lastOne: SchedulerJob | undefined
if (!(job.flags! & SchedulerJobFlags.QUEUED)) {
if (job.id == null) {
queue.push(job)
} else if (
// fast path when the job id is larger than the tail
!(job.flags! & SchedulerJobFlags.PRE) &&
job.id >= (queue[queue.length - 1]?.id || 0)
job.id >= (((lastOne = queue[queue.length - 1]) && lastOne.id) || 0)
) {
queue.push(job)
} else {
Expand Down
5 changes: 4 additions & 1 deletion packages/runtime-vapor/src/warning.ts
Expand Up @@ -30,7 +30,10 @@ export function warn(msg: string, ...args: any[]) {
instance,
VaporErrorCodes.APP_WARN_HANDLER,
[
msg + args.map(a => a.toString?.() ?? JSON.stringify(a)).join(''),
msg +
args
.map(a => (a.toString && a.toString()) ?? JSON.stringify(a))
.join(''),
instance,
trace
.map(
Expand Down

0 comments on commit 9346f88

Please sign in to comment.