I would like to use memoization technique in TypeScript's classes using memoizee
library.
Here is some code of what have I already tried:
import memoize from "memoizee"
import { getModule, Module, MutationAction, VuexModule } from "vuex-module-decorators"
import store from "@/store"
import { User } from "./models"
import { UserAPI } from "./api"
@Module({ namespaced: true, name: "user", store, dynamic: true })
class UserModule extends VuexModule {
user: User | null = null
getUser = memoize(UserAPI.getUser, { maxAge: 10 * 60 * 1000, promise: true })
@MutationAction
async fetchProfile() {
const user = await this.getUser()
return { user }
}
}
export default getModule(UserModule)
Unfortunatelly, it is invalid because TypeError: this.getUser is not a function
.
Why is that? And how to properly use memoizee in TypeScript's classes?
You probably need to import memoize differently.
Here's what worked for me: