Skip to content

Commit

Permalink
fix: injection_return undefined, close #138
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed May 20, 2021
1 parent c796152 commit 1e40ca8
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 34 deletions.
68 changes: 37 additions & 31 deletions packages/client/modules/directives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,25 @@ export default function createDirectives() {

const prev = elements?.value?.length || 0

if (!elements?.value?.includes(el))
if (elements && !elements?.value?.includes(el))
elements.value.push(el)

el?.classList.toggle(CLASS_VCLICK_TARGET, true)

watch(
clicks,
() => {
const c = clicks?.value ?? 0
const show = dir.value != null
? c >= dir.value
: c > prev
if (!el.classList.contains(CLASS_VCLICK_HIDDEN_EXP))
el.classList.toggle(CLASS_VCLICK_HIDDEN, !show)
},
{ immediate: true },
)
if (clicks) {
watch(
clicks,
() => {
const c = clicks?.value ?? 0
const show = dir.value != null
? c >= dir.value
: c > prev
if (!el.classList.contains(CLASS_VCLICK_HIDDEN_EXP))
el.classList.toggle(CLASS_VCLICK_HIDDEN, !show)
},
{ immediate: true },
)
}
},
unmounted(el: HTMLElement, dir) {
el?.classList.toggle(CLASS_VCLICK_TARGET, false)
Expand All @@ -72,15 +74,17 @@ export default function createDirectives() {

el?.classList.toggle(CLASS_VCLICK_TARGET, true)

watch(
clicks,
() => {
const show = (clicks.value ?? 0) >= (dir.value ?? prev ?? 0)
if (!el.classList.contains(CLASS_VCLICK_HIDDEN_EXP))
el.classList.toggle(CLASS_VCLICK_HIDDEN, !show)
},
{ immediate: true },
)
if (clicks) {
watch(
clicks,
() => {
const show = (clicks.value ?? 0) >= (dir.value ?? prev ?? 0)
if (!el.classList.contains(CLASS_VCLICK_HIDDEN_EXP))
el.classList.toggle(CLASS_VCLICK_HIDDEN, !show)
},
{ immediate: true },
)
}
},
unmounted(el: HTMLElement) {
el?.classList.toggle(CLASS_VCLICK_TARGET, true)
Expand All @@ -99,15 +103,17 @@ export default function createDirectives() {

el?.classList.toggle(CLASS_VCLICK_TARGET, true)

watch(
clicks,
() => {
const hide = (clicks?.value || 0) > dir.value
el.classList.toggle(CLASS_VCLICK_HIDDEN, hide)
el.classList.toggle(CLASS_VCLICK_HIDDEN_EXP, hide)
},
{ immediate: true },
)
if (clicks) {
watch(
clicks,
() => {
const hide = (clicks?.value || 0) > dir.value
el.classList.toggle(CLASS_VCLICK_HIDDEN, hide)
el.classList.toggle(CLASS_VCLICK_HIDDEN_EXP, hide)
},
{ immediate: true },
)
}
},
unmounted(el, dir) {
el?.classList.toggle(CLASS_VCLICK_TARGET, false)
Expand Down
2 changes: 1 addition & 1 deletion packages/client/setup/root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default function setupRoot() {
if (+serverState.value.page !== +currentPage.value || clicks.value !== serverState.value.clicks) {
router.replace({
path: getPath(serverState.value.page),
query: { ...router.currentRoute.query, clicks: serverState.value.clicks || 0 },
query: { ...router.currentRoute.value.query, clicks: serverState.value.clicks || 0 },
})
}
},
Expand Down
6 changes: 4 additions & 2 deletions packages/slidev/node/plugins/setupClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ export function createClientSetupPlugin({ clientRoot, themeRoots, userRoot }: Re
imports.push(`import __n${idx} from '${toAtFS(path)}'`)
injections.push(
`// ${path}`,
`injection_return = __n${idx}()`,
(code.includes('injection_return'))
? `injection_return = __n${idx}();`

This comment has been minimized.

Copy link
@SquirrelJimmy

SquirrelJimmy May 20, 2021

injection_return = __n${idx}(injection_arg)injection_arg is Vue context that as defineAppSetup's callback's param in setup/main.ts: defineAppSetup((context: AppContext) => {/*...*/})

This comment has been minimized.

Copy link
@antfu

antfu May 20, 2021

Author Member

Ah, my bad!

: `__n${idx}();`,
)
asyncInjections.push(
`// ${path}`,
`await __n${idx}(injection_arg)`,
`await __n${idx}(injection_arg);`,
)
})

Expand Down

0 comments on commit 1e40ca8

Please sign in to comment.