-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: minor cleanup of filter types and optimizations
- Loading branch information
Showing
4 changed files
with
47 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,38 @@ | ||
import { computed, ComputedRef, MaybeRefOrGetter, toValue } from 'vue'; | ||
import { getFromPath } from '../utils/path'; | ||
import { isObject } from '../../../shared/src'; | ||
// import { computed, ComputedRef, MaybeRefOrGetter, toValue } from 'vue'; | ||
// import { getFromPath } from '../utils/path'; | ||
// import { isObject } from '../../../shared/src'; | ||
|
||
export interface CollectionInit<TItem> { | ||
/** | ||
* The items to be displayed in the collection. | ||
*/ | ||
items: MaybeRefOrGetter<TItem[]>; | ||
/** | ||
* The property to track by, it can be a function that extracts the value from the item. Should be the same as the "value" prop of the option. | ||
*/ | ||
key?: string | ((item: TItem) => unknown); | ||
} | ||
// export interface CollectionInit<TItem> { | ||
// /** | ||
// * The items to be displayed in the collection. | ||
// */ | ||
// items: MaybeRefOrGetter<TItem[]>; | ||
// /** | ||
// * The property to track by, it can be a function that extracts the value from the item. Should be the same as the "value" prop of the option. | ||
// */ | ||
// key?: string | ((item: TItem) => unknown); | ||
// } | ||
|
||
export interface CollectionManager<TItem> { | ||
items: ComputedRef<TItem[]>; | ||
key: (item: TItem) => unknown; | ||
} | ||
// export interface CollectionManager<TItem> { | ||
// items: ComputedRef<TItem[]>; | ||
// key: (item: TItem) => unknown; | ||
// } | ||
|
||
// TODO: Implement fetching, loading, pagination, adding a new item, etc... | ||
export function defineCollection<TItem>(init: CollectionInit<TItem>): CollectionManager<TItem> { | ||
const { items, key } = init; | ||
// // TODO: Implement fetching, loading, pagination, adding a new item, etc... | ||
// export function defineCollection<TItem>(init: CollectionInit<TItem>): CollectionManager<TItem> { | ||
// const { items, key } = init; | ||
|
||
return { | ||
items: computed(() => toValue(items)), | ||
key: | ||
typeof key === 'function' | ||
? key | ||
: item => { | ||
if (key && isObject(item)) { | ||
return getFromPath(item, key, item); | ||
} | ||
// return { | ||
// items: computed(() => toValue(items)), | ||
// key: | ||
// typeof key === 'function' | ||
// ? key | ||
// : item => { | ||
// if (key && isObject(item)) { | ||
// return getFromPath(item, key, item); | ||
// } | ||
|
||
return item; | ||
}, | ||
}; | ||
} | ||
// return item; | ||
// }, | ||
// }; | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export * from './api'; | ||
// export * from './api'; | ||
export * from './filter'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters