Skip to content

Commit dcbc02e

Browse files
committed
feat(pinia-orm): Add HMR support
resolves #1645
1 parent 8dc6efa commit dcbc02e

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

packages/pinia-orm/src/query/Query.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Pinia } from 'pinia'
2+
import { acceptHMRUpdate } from 'pinia'
23
import {
34
assert, compareWithOperator, generateKey,
45
groupBy,
@@ -14,6 +15,7 @@ import { MorphTo } from '../model/attributes/relations/MorphTo'
1415
import type { Model, ModelFields, ModelOptions } from '../model/Model'
1516
import { Interpreter } from '../interpreter/Interpreter'
1617
import { useDataStore } from '../composables/useDataStore'
18+
import type { DataStore } from '../composables/useDataStore'
1719
import type { WeakCache } from '../cache/WeakCache'
1820
import type { CacheConfig } from '../types'
1921
import type { HasMany } from '../model/attributes/relations/HasMany'
@@ -162,6 +164,11 @@ export class Query<M extends Model = Model> {
162164
*/
163165
protected commit (name: string, payload?: any) {
164166
const store = useDataStore(this.model.$storeName(), this.model.$piniaOptions(), this)(this.pinia)
167+
168+
if (import.meta.hot) {
169+
import.meta.hot.accept(acceptHMRUpdate(store as DataStore, import.meta.hot))
170+
}
171+
165172
if (name && typeof store[name] === 'function') { store[name](payload, false) }
166173

167174
if (this.cache && ['get', 'all', 'insert', 'flush', 'delete', 'update', 'destroy'].includes(name)) { this.cache.clear() }

packages/pinia-orm/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"strict": true,
1919
"strictNullChecks": true,
2020
"target": "esnext",
21-
"types": ["nanoid", "@types/node", "vitest/globals", "@types/uuid"],
21+
"types": ["nanoid", "@types/node", "vitest/globals", "@types/uuid", "vite/client"],
2222
"paths": {
2323
"@": [
2424
"./src"

packages/pinia-orm/vite.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default defineConfig({
1616
enabled: true,
1717
reporter: ['lcov', 'text', 'html'],
1818
include: ['src/**/*.ts'],
19-
exclude: ['src/index.ts', 'src/index.cjs.ts']
19+
exclude: ['src/index.ts', 'src/cache/*']
2020
}
2121
},
2222
enabled: true

0 commit comments

Comments
 (0)