-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
48 additions
and
23 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,14 +1,14 @@ | ||
import { helper } from '@ember/component/helper'; | ||
import { isEmpty } from '@ember/utils'; | ||
import { A as emberArray } from '@ember/array'; | ||
import { get } from "@ember/object"; | ||
import asArray from '../utils/as-array.ts'; | ||
|
||
export function findBy<T>([byPath, value, array]: [keyof T, T[keyof T], T[]]) { | ||
if (isEmpty(byPath)) { | ||
return []; | ||
} | ||
|
||
return emberArray(asArray(array)).findBy(byPath, value); | ||
return asArray(array).find((item) => get(item, String(byPath)) === value); | ||
} | ||
|
||
export default helper(findBy); |
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
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,16 +1,19 @@ | ||
import { A as emberArray } from '@ember/array'; | ||
import isEqual from '../utils/is-equal.ts'; | ||
import isEqual from "../utils/is-equal.ts"; | ||
|
||
export default function getIndex<T>(array: T[], currentValue: T, useDeepEqual: boolean) { | ||
export default function getIndex<T>( | ||
array: T[], | ||
currentValue: T, | ||
useDeepEqual: boolean | ||
) { | ||
let needle = currentValue; | ||
|
||
if (useDeepEqual) { | ||
needle = emberArray(array).find((object) => { | ||
needle = array.find((object) => { | ||
return isEqual(object, currentValue, useDeepEqual); | ||
}) as T; | ||
} | ||
|
||
let index = emberArray(array).indexOf(needle); | ||
let index = (array || []).indexOf(needle); | ||
|
||
return index >= 0 ? index : null; | ||
} |
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
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
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