Skip to content

Conversation

@mkzhx
Copy link

@mkzhx mkzhx commented Sep 4, 2022

No description provided.

@mkzhx mkzhx requested a review from ephox-mogran September 4, 2022 23:37
@lgtm-com
Copy link

lgtm-com bot commented Sep 4, 2022

This pull request introduces 12 alerts and fixes 3 when merging 829d563 into e1e5f41 - view on LGTM.com

new alerts:

  • 11 for Unused variable, import, function or class
  • 1 for Duplicate character in character class

fixed alerts:

  • 3 for Unused variable, import, function or class

Copy link

@ephox-mogran ephox-mogran left a comment

Choose a reason for hiding this comment

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

Looks good.

How did you find it?

<!--
<script
src="https://cdn.tiny.cloud/1/7wn8emqewsyc737d25kijfc0xlautpx1jjorbvsdqqu38w85/tinymce/6/tinymce.min.js"
referrerpolicy="origin"

Choose a reason for hiding this comment

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

So, can you remember what referrerpoilcy is for :) ?

Copy link
Author

Choose a reason for hiding this comment

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

From what I can recall:
referrerpolicy specifies the header of requests to the server. When it is set to origin, it would be set to the base url, which is beneficial for the customer because it encourages all requests to cache to the same place and retrieve from that cache too, speeding things up. It's also beneficial for us as it would reduce the number of editor loads.

export const width = (b: Boundz): number => b.x2 - b.x1;

// DONE implement height function
export const height = (b: Boundz): number => b.y2 - b.y1;

Choose a reason for hiding this comment

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

What about if y1 > y2 and the bounds didn't have to be top-left to bottom-right. How would you model height then?

Copy link
Author

Choose a reason for hiding this comment

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

Math.abs(b.y1 - b.y2)

{ name: 'frog2', ribbits: false, age: 4 },
{ name: 'loudfrog', ribbits: true, age: 1 },
{ name: 'quietfrog', ribbits: false, age: 10 },
{ name: "frog1", ribbits: true, age: 3 },

Choose a reason for hiding this comment

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

Correct your linting!

Copy link
Author

@mkzhx mkzhx Sep 7, 2022

Choose a reason for hiding this comment

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

Yeah good point, I'm trying to configure my formatter to use the linting rules in .editorConfig and .eslintrc.json in the main tinymce repo. Do you use a JS/TS formatter like Prettier?


// DONE: Write a function that converts an A[] to an Optional<A>. If the array has more than one element, only consider the first element.
export const arrayToOptional = <A>(arr: A[]): Optional<A> =>
arr.length === 0 ? Optional.none() : Optional.some(arr[0]);

Choose a reason for hiding this comment

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

Nice. It's not uncommon for people to put Optional.from here for arr[0], but that's incorrect. What you have is correct. The some value can be undefined or null in strange cases.

*/

const getOrElse1Constant = <A>(oa: Optional<A>, other: A): A =>
oa.fold(constant(other), Fun.identity);

Choose a reason for hiding this comment

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

In what situation would you avoid using constant do you think?

Copy link
Author

Choose a reason for hiding this comment

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

Within the context of the getOrElse1 function, I can't think of a situation where constant needs to be avoided.

it("toPositiveInteger", () => {
// DONE: write a few test cases
assert.isTrue(Ex.toPositiveInteger(5).equals(Optional.some(5)));
assert.isTrue(Ex.toPositiveInteger(0).isNone());

Choose a reason for hiding this comment

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

Is 0 not a positive integer? Is there a definitive answer on this somewhere?

Copy link
Author

Choose a reason for hiding this comment

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

I've always considered 0 as neither negative nor positive. Some literature specify "non-negative" integers to specify 0 and positive integers.

assert.deepEqual(Ex.optionalToArray(Optional.none()), []);
});

it("arrayToOptional", () => {

Choose a reason for hiding this comment

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

Testing arrays of null and undefined would be good as well.

Copy link
Author

Choose a reason for hiding this comment

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

Good point,
for optionalToArray:

    assert.deepEqual(Ex.optionalToArray(Optional.some(undefined)), [undefined]);
    assert.deepEqual(Ex.optionalToArray(Optional.some(null)), [null]);

for arrayToOptional:

    assert.isTrue(Ex.arrayToOptional([undefined, undefined, undefined]).equals(
        Optional.some(undefined)
      )
    );
    assert.isTrue(
      Ex.arrayToOptional([null, null, null]).equals(Optional.some(null))
    );

@mkzhx mkzhx closed this Oct 23, 2023
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.

3 participants