Implementing memoization in TypeScript classes using the memoizee
library is something I would like to explore.
Below is some code showcasing my initial attempts:
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)
However, an error occurs stating that
TypeError: this.getUser is not a function
.
What could be causing this issue? How can I correct it and effectively utilize memoizee in TypeScript's classes?