Skip to content

Commit

Permalink
feat: add composable cache
Browse files Browse the repository at this point in the history
  • Loading branch information
LinusBorg committed Nov 7, 2022
1 parent 83fe374 commit 0838c4b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
7 changes: 0 additions & 7 deletions src/cache.ts

This file was deleted.

8 changes: 8 additions & 0 deletions src/createComposable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ import type {
} from './types'
import { resolveInjections } from './inject'

export const cache = new Map<any, any>() // TODO: properly type this

export /* @__PURE__ */ function createComposableFromMixin<
Props extends Readonly<ExtractPropTypes<PropsOptions>> & EmitsToProps<E>,
VM extends CreateComponentPublicInstance<
Expand Down Expand Up @@ -118,6 +120,10 @@ export /* @__PURE__ */ function createComposableFromMixin<
// mixins,
} = mixin

if (cache.has(mixin)) {
return cache.get(mixin) as any
}

const composable = () => {
const instance = getCurrentInstance()!
const vm = instance.proxy! as VM
Expand Down Expand Up @@ -219,6 +225,8 @@ export /* @__PURE__ */ function createComposableFromMixin<
props,
emits,
})

cache.set(mixin, composable)
return composable as typeof composable & { props: PropsOptions; emits: E }
}

Expand Down

0 comments on commit 0838c4b

Please sign in to comment.