Skip to content

Commit 31cf7a7

Browse files
committed
clean up
1 parent e1a0527 commit 31cf7a7

File tree

6 files changed

+14
-13
lines changed

6 files changed

+14
-13
lines changed

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export default function feathersVuex(feathers, options: FeathersVuexOptions) {
8282

8383
return {
8484
makeServicePlugin,
85-
BaseModel: BaseModel as ModelStatic,
85+
BaseModel,
8686
makeAuthPlugin,
8787
FeathersVuex,
8888
models: models as GlobalModels,

src/service-module/make-base-model.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import {
1111
ModelStatic,
1212
GlobalModels,
1313
StoreState,
14-
AnyData
14+
AnyData,
15+
PatchParams
1516
} from './types'
1617
import { globalModels, prepareAddModel } from './global-models'
1718
import { mergeWithAccessors, checkNamespace, getId, Params } from '../utils'
@@ -93,8 +94,8 @@ export default function makeBaseModel(options: FeathersVuexOptions) {
9394
} = {}
9495

9596
public __id: string
96-
public __isClone: true
97-
public data: Record<string, any>
97+
public __isClone: boolean
98+
public __isTemp: boolean
9899

99100
public static merge = mergeWithAccessors
100101
public static modelName = 'BaseModel'
@@ -365,7 +366,7 @@ export default function makeBaseModel(options: FeathersVuexOptions) {
365366
* Calls service patch with the current instance data
366367
* @param params
367368
*/
368-
public patch(params?: Params): Promise<this> {
369+
public patch<D extends {} = AnyData>(params?: PatchParams<D>): Promise<this> {
369370
const { idField, _dispatch } = this.constructor as typeof BaseModel
370371
const id = getId(this, idField)
371372

src/service-module/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ export interface FeathersVuexGlobalModels {
7878
export type StoreState = keyof FeathersVuexStoreState extends never ? any : FeathersVuexStoreState
7979
export type GlobalModels = keyof FeathersVuexGlobalModels extends never ? any : FeathersVuexGlobalModels
8080

81-
interface PatchParams<D> extends Params {
82-
data: Partial<D>
81+
export interface PatchParams<D extends {} = AnyData> extends Params {
82+
data?: Partial<D>
8383
}
8484

8585
export interface ModelSetupContext {

src/useFind.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ interface UseFindData<M> {
4545
latestQuery: Ref<object>
4646
paginationData: Ref<object>
4747
error: Ref<Error>
48-
find(params: Params | Ref<Params>): Promise<M[] | Paginated<M>>
48+
find(params?: Params | Ref<Params>): Promise<M[] | Paginated<M>>
4949
}
5050

5151
const unwrapParams = (params: Params | Ref<Params>): Params =>
@@ -123,7 +123,7 @@ export default function find<M extends Model = Model>(options: UseFindOptions):
123123
servicePath: computed<string>(() => model.servicePath)
124124
}
125125

126-
function find(params: Params | Ref<Params>): Promise<M[] | Paginated<M>> {
126+
function find(params?: Params | Ref<Params>): Promise<M[] | Paginated<M>> {
127127
params = unwrapParams(params)
128128
if (queryWhen.value && !state.isLocal) {
129129
state.isPending = true

src/useGet.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ interface UseGetData<M> {
3636
hasLoaded: Ref<boolean>
3737
isLocal: Ref<boolean>
3838
error: Ref<Error>
39-
get(id, params?: Params): Promise<M | undefined>
39+
get(id: Id, params?: Params): Promise<M | undefined>
4040
}
4141

4242
export default function get<M extends Model = Model>(options: UseGetOptions): UseGetData<M> {
@@ -84,8 +84,8 @@ export default function get<M extends Model = Model>(options: UseGetOptions): Us
8484

8585

8686

87-
function get(id, params?: Params): Promise<M | undefined> {
88-
const idToUse = isRef(id) ? id.value : id
87+
function get(id: Id, params?: Params): Promise<M | undefined> {
88+
const idToUse = isRef<Id>(id) ? id.value : id
8989
const paramsToUse = isRef(params) ? params.value : params
9090

9191
if (idToUse != null && queryWhen.value && !state.isLocal) {

test/use/get.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ describe('use/get', function() {
148148
assert(isRef(hasBeenRequested))
149149
assert(hasBeenRequested.value === false, 'no request during init')
150150

151-
get()
151+
get(id)
152152

153153
assert(hasBeenRequested.value === false, 'no request after get')
154154
})

0 commit comments

Comments
 (0)