Skip to content

Commit

Permalink
perf: improve memory usage
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed May 8, 2020
1 parent 1f235a0 commit e3f7221
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
11 changes: 4 additions & 7 deletions src/server-prefetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@ import {
onServerPrefetch as onPrefetch,
getCurrentInstance,
} from '@vue/composition-api'
import { ComponentInstance } from '@vue/composition-api/dist/component'

const ssrRefFunctions = new Map<
ReturnType<typeof getCurrentInstance>,
(() => void)[]
>()

const isPending = new Map<ReturnType<typeof getCurrentInstance>, number>()
const ssrRefFunctions = new WeakMap<ComponentInstance, (() => void)[]>()
const isPending = new WeakMap<ComponentInstance, number>()

let noSetup: Array<() => any> = []

Expand Down Expand Up @@ -40,7 +37,7 @@ export function onServerPrefetch(cb: () => any) {
})
}

export function onServerPrefetchEnd(cb: () => any) {
export function onFinalServerPrefetch(cb: () => any) {
if (!process.server) return

const vm = getCurrentInstance()
Expand Down
5 changes: 2 additions & 3 deletions src/ssr-ref.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ref, Ref } from '@vue/composition-api'
import { onServerPrefetchEnd } from './server-prefetch'
import { onFinalServerPrefetch } from './server-prefetch'

function getValue<T>(value: T | (() => T)): T {
if (value instanceof Function) return value()
Expand Down Expand Up @@ -38,11 +38,10 @@ export const ssrRef = <T>(value: T | (() => T), key?: string): Ref<T> => {
const initVal = clone(val)
const _ref = ref(val) as Ref<T>

onServerPrefetchEnd(() => {
onFinalServerPrefetch(() => {
if (value instanceof Function || initVal !== _ref.value)
data[key] = _ref.value
})

return _ref

}

0 comments on commit e3f7221

Please sign in to comment.