|
1 | 1 | import ObjectID from 'isomorphic-mongo-objectid' |
| 2 | +import type { Ref } from 'vue-demi' |
2 | 3 | import type { CloneOptions } from '../stores/index.js' |
3 | 4 | import type { AnyData, ById, Params } from '../types.js' |
4 | 5 | import { defineValues } from '../utils/define-properties' |
5 | 6 | import type { BaseModelData, ModelInstanceData, StoreInstanceProps } from './types.js' |
6 | 7 |
|
7 | 8 | interface UseModelInstanceOptions<M, Q extends AnyData> { |
8 | 9 | idField: string |
9 | | - clonesById: ById<AnyData> |
| 10 | + clonesById: Ref<ById<AnyData>> |
10 | 11 | clone: (item: M, data?: Record<string, any>, options?: CloneOptions) => M |
11 | 12 | commit: (item: M, data?: Partial<M>) => M |
12 | 13 | reset: (item: M, data?: Record<string, any>) => M |
@@ -39,7 +40,7 @@ export function useModelInstance<M extends AnyData, Q extends AnyData>(data: Mod |
39 | 40 | __tempId: data[idField] == null && data.__tempId == null ? new ObjectID().toString() : data.__tempId || undefined, |
40 | 41 | hasClone(this: M) { |
41 | 42 | const id = this[this.__idField] || this.__tempId |
42 | | - const item = clonesById[id] |
| 43 | + const item = clonesById.value[id] |
43 | 44 | return item || null |
44 | 45 | }, |
45 | 46 | clone(this: M, data: Partial<M> = {}, options: CloneOptions = {}) { |
|
0 commit comments