Skip to content

Commit 24de582

Browse files
committed
add merge to ModelStatic interface
1 parent f204e19 commit 24de582

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/service-module/types.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,31 @@ export interface ModelStatic<D extends {} = AnyData> extends EventEmitter {
186186
[key: number]: ModelClone<D> | undefined
187187
}
188188

189+
/**
190+
* The BaseModel constructor calls mergeWithAccessors(this, newData).
191+
* This utility function correctly copies data between both regular
192+
* objects and Vue.observable instances. If you create a class where
193+
* you need to do your own merging, you probably don't want
194+
* mergeWithAccessors to run twice. In this case, you can use the
195+
* `merge: false` BaseModel instance option to prevent the internal
196+
* merge. You can then access the mergeWithAccessors method by calling
197+
* this method like MyModel.merge(this, newData).
198+
* @param dest destination object
199+
* @param source source object
200+
* @param blacklist keys to ignore when merging
201+
* @example
202+
* class Todo extends BaseModel {
203+
* public constructor(data, options?) {
204+
* options.merge = false // Prevent the internal merge
205+
* super(data, options)
206+
* // ... your custom constructor logic happens here.
207+
* // Call the static merge method to do your own merging.
208+
* Todo.merge(this, data)
209+
* }
210+
* }
211+
*/
212+
merge(dest: unknown, source: unknown, blacklist?: string[]): void
213+
189214
/**
190215
* Create new Model
191216
* @param data partial model data

0 commit comments

Comments
 (0)