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

Composite Refactoring with Strategies #157

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from
Open

Conversation

beshur
Copy link
Member

@beshur beshur commented Dec 4, 2019

No description provided.

{
hosts: [ 'radiolist.com.ua' ],
options: {
statusStrategy: StatusStrategies.checkSelector,
Copy link
Member

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")

Copy link
Member Author

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));
Copy link
Member

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?

Copy link
Member

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.

Copy link
Member Author

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;
}
Copy link
Member

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;
}

Copy link
Member Author

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/Status.Strategies.js Outdated Show resolved Hide resolved
src/content/Status.Strategies.js Outdated Show resolved Hide resolved
src/content/Control.Strategies.js Show resolved Hide resolved
src/content/Control.Strategies.js Outdated Show resolved Hide resolved
src/content/Control.Strategies.js Outdated Show resolved Hide resolved
}

static play() {
clickSelector.pause();
Copy link
Member

Choose a reason for hiding this comment

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

looks funny :))))
play() => pause()

Copy link
Member Author

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.

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.

2 participants