Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add typeArray and allow passing equal function to bindableDerived #175

Merged
merged 1 commit into from
Oct 5, 2023

Conversation

MarkoOleksiyenko
Copy link
Contributor

No description provided.

@codecov
Copy link

codecov bot commented Oct 4, 2023

Codecov Report

Merging #175 (b7ca1aa) into main (55773bc) will increase coverage by 0.05%.
Report is 1 commits behind head on main.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #175      +/-   ##
==========================================
+ Coverage   89.11%   89.17%   +0.05%     
==========================================
  Files          61       61              
  Lines        1488     1496       +8     
  Branches      232      234       +2     
==========================================
+ Hits         1326     1334       +8     
  Misses        125      125              
  Partials       37       37              
Flag Coverage Δ
e2e-1 63.78% <58.82%> (-0.19%) ⬇️
e2e-2 40.63% <58.82%> (-0.03%) ⬇️
e2e-4 66.44% <58.82%> (-0.23%) ⬇️
e2e-5 50.19% <58.82%> (-0.10%) ⬇️
e2e-7 59.15% <58.82%> (-0.21%) ⬇️
e2e-8 58.33% <58.82%> (-0.20%) ⬇️
unit 91.52% <100.00%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
core/lib/services/checks.ts 100.00% <100.00%> (ø)
core/lib/services/stores.ts 98.98% <100.00%> (+0.01%) ⬆️
core/lib/services/writables.ts 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

* @param value the value to check
* @returns true if the value is an array
*/
export function isArray(value: any) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export function isArray(value: any) {
export function isArray(value: any): value is any[] {

(cf https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates)

* @param value the value to check
* @returns true if the value is an array
*/
export function isArray(value: any) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe we should do:

export const isArray = Array.isArray;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems more concise!

const testArray = [15, 20];
store$.set(testArray);

expect(store$()).toStrictEqual([15, 20]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expect(store$()).toStrictEqual([15, 20]);
expect(store$()).toBe(testArray);

expect(typeArray.equal(arr, arr2)).toBe(true);
expect(typeArray.equal([15], [15, 15])).toBe(false);
expect(typeArray.equal([15, 15], [15])).toBe(false);
expect(typeArray.equal(undefined, [15])).toBe(false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undefined is not part of the accepted types for this equal function.
You should do undefined as any if you still want to test this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true, will type the method params


expect(store$()).toStrictEqual([15, 20]);

testArray[1] = 15;
Copy link
Member

@divdavem divdavem Oct 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not really in favor of using stores this way. I prefer immutability, otherwise we need equal functions that consider objects as always different (even when they are the same reference). I would remove this part of the test.


export const typeArray: WritableWithDefaultOptions<any[]> = {
normalizeValue: testToNormalizeValue(isArray),
equal: (a: any[], b: any[]) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
equal: (a: any[], b: any[]) => {
equal: (a, b) => {

(the type of equal is already implied by WritableWithDefaultOptions<any[]> line 27)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is, however, the IDE highlights it in red saying that it as implicit type

@MarkoOleksiyenko MarkoOleksiyenko merged commit 77f3dcf into AmadeusITGroup:main Oct 5, 2023
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants