-
-
Notifications
You must be signed in to change notification settings - Fork 78
Replace runtime imports with static imports #148
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
Closed
alexanderroidl
wants to merge
1
commit into
orangecoding:master
from
alexanderroidl:refactor/replace-runtime-imports-with-static-imports
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,15 +1,11 @@ | ||
import fs from 'fs'; | ||
import restana from 'restana'; | ||
import providers from '../../provider/index.js'; | ||
|
||
const service = restana(); | ||
const providerRouter = service.newRouter(); | ||
const providerList = fs.readdirSync('./lib/provider').filter((file) => file.endsWith('.js')); | ||
const provider = await Promise.all( | ||
providerList.map(async (pro) => { | ||
return await import(`../../provider/${pro}`); | ||
}) | ||
); | ||
|
||
providerRouter.get('/', async (req, res) => { | ||
res.body = provider.map((p) => p.metaInformation); | ||
res.body = providers.map((p) => p.metaInformation); | ||
res.send(); | ||
}); | ||
export { providerRouter }; |
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import * as apprise from './apprise.js'; | ||
import * as console from './console.js'; | ||
import * as mailJet from './mailJet.js'; | ||
import * as mattermost from './mattermost.js'; | ||
import * as ntfy from './ntfy.js'; | ||
import * as pushover from './pushover.js'; | ||
import * as sendGrid from './sendGrid.js'; | ||
import * as slack from './slack.js'; | ||
import * as sqlite from './sqlite.js'; | ||
import * as telegram from './telegram.js'; | ||
|
||
export default [apprise, console, mailJet, mattermost, ntfy, pushover, sendGrid, slack, sqlite, telegram]; |
This file contains hidden or 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 hidden or 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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import * as einsAImmobilien from './einsAImmobilien.js'; | ||
import * as immobilienDe from './immobilienDe.js'; | ||
import * as immonet from './immonet.js'; | ||
import * as immoscout from './immoscout.js'; | ||
import * as immoswp from './immoswp.js'; | ||
import * as immowelt from './immowelt.js'; | ||
import * as kleinanzeigen from './kleinanzeigen.js'; | ||
import * as neubauKompass from './neubauKompass.js'; | ||
import * as wgGesucht from './wgGesucht.js'; | ||
|
||
export default [ | ||
einsAImmobilien, | ||
immobilienDe, | ||
immonet, | ||
immoscout, | ||
immoswp, | ||
immowelt, | ||
kleinanzeigen, | ||
neubauKompass, | ||
wgGesucht, | ||
]; |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know I know, this makes things more performant.. BUT, that comes with a price. The reason I did it the way it is today is because ease of use. You can simply add a new file, throw it into the folder and you can be sure it will be read and it is available. You do not need to register it somewhere. This ease of use of course comes with the price of a little bit of performance, but since Fredy is not rly a high performant app, I'm willing to pay the price.
What's your take on this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I understand how there is convenience to importing the files like so I would avoid it here because it requires us implementing loading logic ourselves to a certain degree while all functionality we need is already available natively.
I would avoid implementing anything around runtime-loading application parts, as it's not necessary for the project, we have a set number of providers and adapters. They don't change during runtime, plus there is an existing system for indexing them in directories.
What we have here is a cool idea but highly uncommon and desirable to avoid IMO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I totally get your point and usually would agree though I still think for this very case, I don't see a real reason of changing this to a way that makes it more complicated for those trying to implement provider. Again I fully see your point and in an app that is resource-critical, I would never do it this way, but for Fredy, I still think this is better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regardless of performance I don't think our case justifies a custom loading implementation. I would expect anybody implementing a provider capable of adding to the index too and it not being too much of an extra effort
But other than that, I would like for providers and notif. adapters to use their own directory and multiple files. That would mean we would have to further complicate our logic to support this :/ What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the benefit of having their own folder? Mostly structurally 'cleanup' (less cluttered)?