Skip to content

Composite Refactoring with Strategies#157

Open
beshur wants to merge 15 commits intodevelopfrom
refactor-strategies
Open

Composite Refactoring with Strategies#157
beshur wants to merge 15 commits intodevelopfrom
refactor-strategies

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.

}

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