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

Type script #17

Merged
merged 112 commits into from
Apr 14, 2020
Merged

Type script #17

merged 112 commits into from
Apr 14, 2020

Conversation

aminya
Copy link
Contributor

@aminya aminya commented Mar 7, 2020

Ready to get merged - Tested and works as expected

before:

image

after:

image

  • Added configuration for TypeScript
  • Added type declaration/annotations for some of the variables
  • Added TODOs for improving the code
  • Added Tests
  • Added Benchmarks

/src includes the typescript source files (input).
/lib includes the compiled javascript (output).

  • Squashed and remade the history based on @aviatesk suggestion.

@aminya aminya force-pushed the TypeScript branch 6 times, most recently from 39bf64d to c8d2143 Compare March 8, 2020 07:35
@pfitzseb
Copy link
Member

pfitzseb commented Mar 9, 2020

Neat, let me know when you think this is done.

Aside: I'd very much prefer no semi-colons -- they're not very useful in JS, and TS has even fewer corner cases where ;s do something.

@aminya
Copy link
Contributor Author

aminya commented Mar 9, 2020

Neat, let me know when you think this is done.

I am facing a problem with importing a class from atom-select-list:
https://stackoverflow.com/questions/60599391/calling-javascript-class-from-typescript-uncaught-typeerror-is-not-a-const

Do you know what is going on here?

@aminya

This comment has been minimized.

@aminya
Copy link
Contributor Author

aminya commented Mar 9, 2020

Neat, let me know when you think this is done.

I am facing a problem with importing a class from atom-select-list:
stackoverflow.com/questions/60599391/calling-javascript-class-from-typescript-uncaught-typeerror-is-not-a-const
Do you know what is going on here?

I think this is fixed in 1b597d1, but I get a new error:
Error:

This is solved in bf753d4 🚀

@aminya
Copy link
Contributor Author

aminya commented Mar 9, 2020

@pfitzseb This is ready to get merged for now. 😃

  • I have added some TODOs for future development.

PS: the name of the package doesn't match the name of the repository. If this isn't intentional, we should fix it.

@aminya aminya force-pushed the TypeScript branch 3 times, most recently from e692128 to 16dd7d0 Compare March 10, 2020 04:08
@aminya
Copy link
Contributor Author

aminya commented Mar 10, 2020

This is very ready to get merged 😄 @pfitzseb

I fixed #15 by using a StatusBar Class instead of a module.

@aminya aminya force-pushed the TypeScript branch 4 times, most recently from 3339a3b to 053b0ec Compare March 15, 2020 07:10
@aminya aminya mentioned this pull request Mar 15, 2020
62 tasks
@aviatesk
Copy link
Member

My thoughts on this:

  • the changes are too big to be safely merged; in general it's better to split changes into small PRs as possible https://rangle.io/blog/the-art-of-humanizing-pull-requests-prs/
  • imho TypeScript would be not so fruitful but bothersome for this package
    • we need to sync the version of TS
    • this is such a small package that we can easily track its implementation and we don't really need to rely on type information; code would be verbose
    • TS should be introduced when really necessary, and in this case it's not imho
    • (well, I'm not just object to static-typing -- we use flow for Hydrogen for example, and I feel the type checking for a package in that scale is useful; my idea is about the balance between the verboseness/bothersome vs. usefulness of it)

@aminya
Copy link
Contributor Author

aminya commented Mar 17, 2020

My thoughts on this:

* the changes are too big to be safely merged; in general it's better to split changes into small PRs as possible [rangle.io/blog/the-art-of-humanizing-pull-requests-prs](https://rangle.io/blog/the-art-of-humanizing-pull-requests-prs/)
  
  * it's great that fixing #15 but it's better to be done in a separate PR

Thank you for your opinion.

Regarding your first point, I totally get your point regarding small PRs and I agree with it, however, this PR meant to fix the performance of this package, and for that, I had to rewrite different sections of the code, and edits in small chunks were either not possible or didn't help because of code overhaul (e.g. space-pen-views -> atom-select-list).

* imho TypeScript would be not so fruitful but bothersome for this package
  
  * we need to sync the version of TS
  * this is such a small package that we can easily track its implementation and we don't really need to rely on type information; code would be verbose
  * TS should be introduced when really necessary, and in this case it's not imho
  * (well, I'm not just object to static-typing -- we use [flow](https://flow.org/) for [Hydrogen](https://github.com/nteract/hydrogen) for example, and I feel the type checking for a package in that scale is useful; my idea is about the balance between the verboseness/bothersome vs. usefulness of it)

I want to disagree with this one though.

  • You don't need to do anything regarding TS. This package is good to go and will act like a JS package for usage (JS is already built).

  • Typescript isn't about just tracking the implementation. It brings many improvements over simple JavaScript (enhances JS without drawbacks):

    • it reveals many things that are not visible when you use JS. Things like type-changing of the variables, if a function returns the type we want, performance improvement by using better types, etc. You see this package loads 1/4 of the original, and its runtime was better in my measurements (30-50%).
    • IntelliSense/linting
    • API documentation on the fly. It allows others to understand what the code is doing.
    • You can write your normal JS code in TypeScript and it works. TypeScript infers many of the types automatically.
    • It removes the need for babel or any other processor.
    • We can compile TypeScript to Wasm using AssemblyScript which opens a whole new world for improving the package. For example, I plan to compile the getIndet function of this package.
    • The future isn't plain JavaScript. For example, VSCode is already using TS (which IMO has better performance while I like atom more).

Read this article to know more about the advantages:
https://dzone.com/articles/what-is-typescript-and-why-use-it

Add dom to lib

Update tsconfig.json

update tsconfig

import helpers option

tslib deps

  Revert import helpers

compile

Update tsconfig.json
Update package.json
@aminya aminya force-pushed the TypeScript branch 2 times, most recently from bd320dd to 7fa86c0 Compare March 22, 2020 01:58
@aminya
Copy link
Contributor Author

aminya commented Mar 22, 2020

  • I furthered improved the performance in bd320dd by defining a Selector class instead of a module and separating different independent functions from each other.

  • Optimized for loops using (see TypeScript-Optimization):

    • Not looking up arrays in for-head
    • Using babel transform for-of plugin
  • Minify using Babel (very minimalistic)

  • Squashed and remade the history based on @aviatesk suggestion.

@aminya
Copy link
Contributor Author

aminya commented Apr 5, 2020

Could you the benchmark again? I cannot get reproduce your result but I just wanna see if it is improved on your computers.
@pfitzseb @aviatesk

On my system 5ms is reduced to 0 ms:
image

@pfitzseb
Copy link
Member

pfitzseb commented Apr 6, 2020

I'm getting 0ms on both of my machines as well now -- is that just because package activation is deferred because of the activation hook?

@aminya
Copy link
Contributor Author

aminya commented Apr 6, 2020

I'm getting 0ms on both of my machines as well now -- is that just because package activation is deferred because of the activation hook?

Yes. That is why. But before 525aee1 still I got a very good loading time.

My inline benchmark code still gives 5ms. Probably Atom cannot measure the correct activation time especially when it is deferred.

My Github action shows 20ms in the online benchmark: https://github.com/aminya/atom-indent-detective/runs/561525274?check_suite_focus=true#step:6:83. That one is based on atom.packages.activate, which may not be as accurate as the inline benchmark.


The package loads much faster (compared to master branch) because:

@aminya
Copy link
Contributor Author

aminya commented Apr 11, 2020

@pfitzseb Do you need anything else here from me?

@pfitzseb pfitzseb merged commit 5c55a0c into JunoLab:master Apr 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants