-
Notifications
You must be signed in to change notification settings - Fork 3
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
Composite Refactoring with Strategies #157
base: develop
Are you sure you want to change the base?
Conversation
src/content/ServicesRegistry.js
Outdated
{ | ||
hosts: [ 'radiolist.com.ua' ], | ||
options: { | ||
statusStrategy: StatusStrategies.checkSelector, |
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.
We can make it a factory method and get rid off statusArgs.
StatusStrategies.getCheckSelector(".jouele-status-playing .jouele-info-control-button-icon_pause")
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 would keep things generic for all the strategies, i.e. passing the args as a property on the options object, as I see there will be other strategies with a different params count etc.
'.icon-toggle.mod-mute .icon-button.mod-muted', | ||
'.icon-toggle.mod-mute .icon-button.mod-sound' | ||
] | ||
].map(item => oneSelectorHelper.apply(null, item)); |
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.
wow, looks like a magic :)
maybe simple declarative way, like radiolist.com.ua
below?
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 mean, in this case you should always remember what's 2, 3, 4 arguments for.
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.
It's true, but it will be very redundant with the amount of services that we have
status = hasPlayingVideo ? Status.PLAYING : Status.PAUSED; | ||
} | ||
return status; | ||
} |
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.
According to some clean code guides, it's better to leave exclusions in the beginning and do stuff after.
static getStatus() {
let status = Status.PAUSED;
const videos = document.getElementsByTagName("video");
if (videos.length > 0) {
const hasPlayingVideo = Array.from(videos).some((player) => !player.paused);
status = hasPlayingVideo ? Status.PLAYING : Status.PAUSED;
}
return status;
}
becomes
static getStatus() {
const videos = document.getElementsByTagName("video");
if (!videos.length) {
return Status.PAUSED;
}
const hasPlayingVideo = Array.from(videos).some((player) => !player.paused);
return hasPlayingVideo
? Status.PLAYING
: Status.PAUSED;
}
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.
Here I don't have an exclusion - it's the actual condition of continuation.
Also it's always good to have one return
.
I would keep it like this.
src/content/Control.Strategies.js
Outdated
} | ||
|
||
static play() { | ||
clickSelector.pause(); |
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.
looks funny :))))
play() => pause()
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.
The method is static, so it won't work.
Oh, actually, I added separate args here, I'll update.
Co-Authored-By: Oleksandr Karpov <[email protected]>
Co-Authored-By: Oleksandr Karpov <[email protected]>
Co-Authored-By: Oleksandr Karpov <[email protected]>
Co-Authored-By: Oleksandr Karpov <[email protected]>
Co-Authored-By: Oleksandr Karpov <[email protected]>
No description provided.