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

How can we refactor our code? #137

Open
shakeelmohamed opened this issue Jan 16, 2016 · 10 comments
Open

How can we refactor our code? #137

shakeelmohamed opened this issue Jan 16, 2016 · 10 comments

Comments

@shakeelmohamed
Copy link
Member

I made a terrible sin working on zap-cli by copy/pasting some code over to contrib.js.
This is definitely not ideal, and entirely unmaintainable.

What can we do to avoid this?

I'm thinking we could break out utility functions into a new repository, then either

  1. Use git submodules - will we need to use requireJS by doing so? (maybe not if our JS imports are in the right order)
  2. Use bower and npm within that repository (without publishing) so the code can be used on the website, CLI, & Chrome extension
@monicacheung
Copy link
Member

I don't understand what zap-cli is. Can you add some use case?

@shakeelmohamed
Copy link
Member Author

$ zap
Usage: zap <YouTube URL | video ID | search query>

Background: you're a developer, and live in the terminal.

  1. Somebody gives you a YouTube URL
  2. You open a terminal and type zap then paste the URL, then hit enter
  3. The URL gets parsed and http://zen-audio-player.github.io opens in your default browser as either a video lookup or a search

It might be interesting to see if we can play the video within the terminal somehow also

@monicacheung
Copy link
Member

I don't know about Node.js but couldn't it be done in a few lines in a shell script? Something like...

get the status code of "curl -I input or http://youtubeblahblah...input"
if 200 OK, open http://zen-audio-player.github.io/?v=input
else, "open http://zen-audio-player.github.io/?q=input"

Why do we need to have so much dup code?

edit :)

@shakeelmohamed
Copy link
Member Author

Well, that's making an extra HTTP request. Doing it in Node gives us full cross-platform support, and it's actually not that much duplicated code but we can do better.

@shakeelmohamed
Copy link
Member Author

If we do this, we'll need to break out the common logic - then include it via npm/bower. Submodules will be adding too much friction to the process

  • Pro: We will have really solid common code, and can write unit tests.
  • Con: Contributing to any of the 3 projects (website, Chrome extension, CLI) becomes more complicated since editing common code will involve changes to 2 repos

@monicacheung
Copy link
Member

Is there downside of the extra HTTP request? It can let us fail early too.
Refactoring code for the website would be good. But I don't see benefit of reusing code in other projects if what you want can be requested.

@shakeelmohamed
Copy link
Member Author

Is there downside of the extra HTTP request?

Not necessarily, but it's bad design and could add an unwanted amount of delay if the request takes over say 100ms. This isn't an option for the Chrome extension as it needs to be an instant operation, or it will be unusable.

shakeelmohamed pushed a commit that referenced this issue Jan 20, 2016
See #137

When this is actually done, js/zap-common.js
will be moved into a bower module and end up
moving to something like:

bower_components/zap-common/index.js
shakeelmohamed pushed a commit that referenced this issue Jan 20, 2016
See #137

When this is actually done, js/zap-common.js
will be moved into a bower module and end up
moving to something like:

bower_components/zap-common/index.js
shakeelmohamed pushed a commit that referenced this issue Jan 20, 2016
See #137

When this is actually done, js/zap-common.js
will be moved into a bower module and end up
moving to something like:

bower_components/zap-common/index.js
@shakeelmohamed
Copy link
Member Author

Just merged #141! Now I just have to figure out how to move the contents of zap-common.js into the zen-audio-player/zap-common repo

@caseyprovost
Copy link

@shakeelmohamed are you looking to move zap-common into a Bower module that you can then import?

@shakeelmohamed
Copy link
Member Author

@caseyprovost originally that was the idea. It seems that the JavaScript ecosystem has shifted from bower towards webpack and just using node modules - I think we can follow that model to stay modern. Out of that process, we might go ahead and port our codebase to es6 while we're at it if there's a compile step involved in the release process

@shakeelmohamed shakeelmohamed removed their assignment Jun 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants