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

refactor(microservices) refactor, improvements, use es6 map #1161

Merged
merged 30 commits into from
Dec 10, 2018

Conversation

kamilmysliwiec
Copy link
Member

@kamilmysliwiec kamilmysliwiec commented Oct 3, 2018

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[ ] Feature
[x] Code style update (formatting, local variables)
[x] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

[x] Yes
[ ] No

Other information

Breaking change due to the different API of custom transport strategies (microservices)

@coveralls
Copy link

coveralls commented Oct 3, 2018

Pull Request Test Coverage Report for Build 1317

  • 69 of 71 (97.18%) changed or added relevant lines in 21 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.03%) to 93.775%

Changes Missing Coverage Covered Lines Changed/Added Lines %
packages/common/utils/http-exception-body.util.ts 3 4 75.0%
packages/microservices/server/server-nats.ts 6 7 85.71%
Totals Coverage Status
Change from base Build 1282: -0.03%
Covered Lines: 2845
Relevant Lines: 2967

💛 - Coveralls

@@ -43,7 +43,7 @@ export class ServerMqtt extends Server implements CustomTransportStrategy {

public bindEvents(mqttClient: MqttClient) {
mqttClient.on(MESSAGE_EVENT, this.getMessageHandler(mqttClient).bind(this));
const registeredPatterns = Object.keys(this.messageHandlers);
const registeredPatterns = [...this.messageHandlers.keys()];
Copy link

Choose a reason for hiding this comment

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

It could be simplified using this.messageHandlers.keys() instead of [...this.messageHandlers.keys()] 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

Map.keys() returns an Iterator (not an array)

Copy link

Choose a reason for hiding this comment

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

You're correct! Good catch 😆

@@ -40,7 +40,7 @@ export class ServerNats extends Server implements CustomTransportStrategy {
}

public bindEvents(client: Client) {
const registeredPatterns = Object.keys(this.messageHandlers);
const registeredPatterns = [...this.messageHandlers.keys()];
Copy link

Choose a reason for hiding this comment

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

And here

Copy link
Member Author

Choose a reason for hiding this comment

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

as above

@@ -52,7 +52,7 @@ export class ServerRedis extends Server implements CustomTransportStrategy {

public bindEvents(subClient: RedisClient, pubClient: RedisClient) {
subClient.on(MESSAGE_EVENT, this.getMessageHandler(pubClient).bind(this));
const subscribePatterns = Object.keys(this.messageHandlers);
const subscribePatterns = [...this.messageHandlers.keys()];
Copy link

Choose a reason for hiding this comment

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

And here

Copy link
Member Author

Choose a reason for hiding this comment

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

as above

): (data) => Promise<Observable<any>> | null {
return this.messageHandlers[pattern] ? this.messageHandlers[pattern] : null;
public getHandlerByPattern(pattern: string): MessageHandler | null {
return this.messageHandlers.has(pattern)
Copy link

Choose a reason for hiding this comment

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

It's okey, but it could be shorter if you use this.messageHandlers.get(pattern) || null :-)

Copy link
Contributor

Choose a reason for hiding this comment

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

Good!

@@ -80,10 +80,12 @@ describe('ServerGrpc', () => {

describe('createService', () => {
it('should call "createServiceMethod"', async () => {
const handlers = {
const objectToMap = obj =>
Copy link

Choose a reason for hiding this comment

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

This function is used in more places (copy/pasted), maybe it could be put in one place and reuse it

Copy link
Contributor

Choose a reason for hiding this comment

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

Good clean-code

@kamilmysliwiec kamilmysliwiec modified the milestones: 6.00, 6.0.0 Oct 5, 2018
@kamilmysliwiec kamilmysliwiec changed the base branch from master to 6.0.0-next December 10, 2018 21:04
@kamilmysliwiec kamilmysliwiec merged commit f96b2a8 into 6.0.0-next Dec 10, 2018
@delete-merged-branch delete-merged-branch bot deleted the refactor/microservices branch December 10, 2018 21:38
@lock
Copy link

lock bot commented Sep 24, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Sep 24, 2019
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants