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

have fp use meta name option instead of new symbol #44

Merged
merged 4 commits into from Jul 1, 2018

Conversation

Ethan-Arrowood
Copy link
Member

@nwoltman highlighted that fastify uses the fastify-plugin options.name meta option property when adding plugins to the registered-plugin list. In conjunction with the new toString feature (fastify/fastify#861) this PR includes changes that will make fp always assign a function name to the meta option object instead of using an independent symbol (previously added via #37).

Due note that this will change the fundamental behavior of fastify-plugin as it will always assign the Symbol.for('plugin-meta') property to every function passed in.

I kept support for using a version string as the 'options' parameter too.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

Good work!

@@ -11,5 +11,5 @@ test('anonymous function should be named composite.test', t => {
next()
})

t.is(fn[Symbol.for('fastify.display-name')], 'composite.test')
t.is(fn[Symbol.for('plugin-meta')].name, 'composite.test')
Copy link
Member

Choose a reason for hiding this comment

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

Can you name this fastify.plugin-meta?

Choose a reason for hiding this comment

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

If the symbol is changed, this line in the fastify repo would also need to change, so changing the symbol could be considered a breaking change.

Copy link
Member Author

Choose a reason for hiding this comment

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

Would this be considered a breaking change as I'd have to update fasitfy code as well? I'll push a commit asap 👍

Copy link
Member

Choose a reason for hiding this comment

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

Ouch, forget about it!

@@ -11,5 +11,5 @@ test('anonymous function should be named composite.test', t => {
next()
})

t.is(fn[Symbol.for('fastify.display-name')], 'composite.test')
Copy link
Member

Choose a reason for hiding this comment

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

Can you keep fastify.display-name as well? Otherwise it will be a breaking change, and I would not bump the major for this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay I'll keep it in even though it is redundant. Maybe we can make deprecation note for whenever fastify-plugin v2?

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

LGTM

@mcollina mcollina mentioned this pull request Jun 29, 2018
4 tasks
@mcollina
Copy link
Member

@nwoltman @delvedor are you ok for landing this?

index.js Outdated
if (!options.name) {
let name = checkName(fn)
options.name = name
fn[Symbol.for('fastify.display-name')] = name

Choose a reason for hiding this comment

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

To retain full backward compatibility, this symbol should also be set when options.name exists. So this line should be moved after the if block.

@Ethan-Arrowood
Copy link
Member Author

Travis build needs restarting I think. I don't know whats causing some of the builds to complete and then other not.

Anyways, this should be good to go now. I've included a new unit test that verifies a fastify-plugin declared with a meta object also gets the Symbol.for('fastify-display.name') property set.

Once merged and deployed to npm I'll update the fastify dependencies and toString should finally be ready to be merged 😄

index.js Outdated
}

if (typeof options !== 'object' || Array.isArray(options) || options === null) {
throw new TypeError('The options object should be an object')
}

if (!options.name) {
let name = checkName(fn)
options.name = name
Copy link

Choose a reason for hiding this comment

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

This could be simplified to

options.name = checkName(fn)

Copy link

@nwoltman nwoltman left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Copy link
Member

@delvedor delvedor left a comment

Choose a reason for hiding this comment

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

LGTM

@mcollina mcollina merged commit 60832a3 into fastify:master Jul 1, 2018
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.

None yet

4 participants