Skip to content

Commit

Permalink
feat(pinia-orm): Add HMR support
Browse files Browse the repository at this point in the history
resolves #1645
  • Loading branch information
CodeDredd committed Sep 17, 2023
1 parent 8dc6efa commit dcbc02e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
7 changes: 7 additions & 0 deletions packages/pinia-orm/src/query/Query.ts
@@ -1,4 +1,5 @@
import type { Pinia } from 'pinia'
import { acceptHMRUpdate } from 'pinia'
import {
assert, compareWithOperator, generateKey,
groupBy,
Expand All @@ -14,6 +15,7 @@ import { MorphTo } from '../model/attributes/relations/MorphTo'
import type { Model, ModelFields, ModelOptions } from '../model/Model'
import { Interpreter } from '../interpreter/Interpreter'
import { useDataStore } from '../composables/useDataStore'
import type { DataStore } from '../composables/useDataStore'
import type { WeakCache } from '../cache/WeakCache'
import type { CacheConfig } from '../types'
import type { HasMany } from '../model/attributes/relations/HasMany'
Expand Down Expand Up @@ -162,6 +164,11 @@ export class Query<M extends Model = Model> {
*/
protected commit (name: string, payload?: any) {
const store = useDataStore(this.model.$storeName(), this.model.$piniaOptions(), this)(this.pinia)

if (import.meta.hot) {
import.meta.hot.accept(acceptHMRUpdate(store as DataStore, import.meta.hot))
}

if (name && typeof store[name] === 'function') { store[name](payload, false) }

if (this.cache && ['get', 'all', 'insert', 'flush', 'delete', 'update', 'destroy'].includes(name)) { this.cache.clear() }
Expand Down
2 changes: 1 addition & 1 deletion packages/pinia-orm/tsconfig.json
Expand Up @@ -18,7 +18,7 @@
"strict": true,
"strictNullChecks": true,
"target": "esnext",
"types": ["nanoid", "@types/node", "vitest/globals", "@types/uuid"],
"types": ["nanoid", "@types/node", "vitest/globals", "@types/uuid", "vite/client"],
"paths": {
"@": [
"./src"
Expand Down
2 changes: 1 addition & 1 deletion packages/pinia-orm/vite.config.ts
Expand Up @@ -16,7 +16,7 @@ export default defineConfig({
enabled: true,
reporter: ['lcov', 'text', 'html'],
include: ['src/**/*.ts'],
exclude: ['src/index.ts', 'src/index.cjs.ts']
exclude: ['src/index.ts', 'src/cache/*']
}
},
enabled: true
Expand Down

0 comments on commit dcbc02e

Please sign in to comment.