@@ -21,6 +21,7 @@ import _get from 'lodash/get'
21
21
import { EventEmitter } from 'events'
22
22
import { ModelSetupContext } from './types'
23
23
import { Store } from 'vuex'
24
+ import { GetterName } from './service-module.getters'
24
25
25
26
const defaultOptions = {
26
27
clone : false ,
@@ -175,6 +176,34 @@ export default function makeBaseModel(options: FeathersVuexOptions) {
175
176
return this
176
177
}
177
178
179
+ /**
180
+ * Calls `getter`, passing this model's ID as the parameter
181
+ * @param getter name of getter to call
182
+ */
183
+ private getGetterWithId ( getter : GetterName ) : unknown {
184
+ const { _getters, idField, tempIdField } = this
185
+ . constructor as typeof BaseModel
186
+ const id =
187
+ getId ( this , idField ) != null ? getId ( this , idField ) : this [ tempIdField ]
188
+ return _getters . call ( this . constructor , getter , id )
189
+ }
190
+
191
+ get isCreatePending ( ) : boolean {
192
+ return this . getGetterWithId ( 'isCreatePendingById' ) as boolean
193
+ }
194
+ get isUpdatePending ( ) : boolean {
195
+ return this . getGetterWithId ( 'isUpdatePendingById' ) as boolean
196
+ }
197
+ get isPatchPending ( ) : boolean {
198
+ return this . getGetterWithId ( 'isPatchPendingById' ) as boolean
199
+ }
200
+ get isRemovePending ( ) : boolean {
201
+ return this . getGetterWithId ( 'isRemovePendingById' ) as boolean
202
+ }
203
+ get isPending ( ) : boolean {
204
+ return this . getGetterWithId ( 'isPendingById' ) as boolean
205
+ }
206
+
178
207
public static getId ( record : Record < string , any > ) : string {
179
208
const { idField } = this . constructor as typeof BaseModel
180
209
return getId ( record , idField )
@@ -214,7 +243,7 @@ export default function makeBaseModel(options: FeathersVuexOptions) {
214
243
* @param method the vuex getter name without the namespace
215
244
* @param payload if provided, the getter will be called as a function
216
245
*/
217
- public static _getters ( name : string , idOrParams ?: any , params ?: any ) {
246
+ public static _getters ( name : GetterName , idOrParams ?: any , params ?: any ) {
218
247
const { namespace, store } = this
219
248
220
249
if ( checkNamespace ( namespace , this , options . debug ) ) {
0 commit comments