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

feat: consistent function naming with underscores #821

Merged
merged 13 commits into from
Oct 24, 2023

Conversation

norbitrial
Copy link
Contributor

This PR is a solution for #793 issue.

Function calls are tested after renaming and working exact the same way as before. There are extra warnings on the console for old function calls for the following cases:

  • groupby() function call,
  • fromlast() and tofirst() calls.

Let me know if you have any suggestions. Thank you! 🙇 👍

Copy link
Member

@DmitrySharabin DmitrySharabin left a comment

Choose a reason for hiding this comment

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

That's awesome! Thank you. Actually, you already did a great job; there is only one question left. Please see the comments.

src/mavoscript.js Outdated Show resolved Hide resolved
src/mavoscript.js Outdated Show resolved Hide resolved
Copy link
Member

@DmitrySharabin DmitrySharabin left a comment

Choose a reason for hiding this comment

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

That's awesome! Thank you. Actually, you already did a great job; there is only one question left. Please see the comments.

@DmitrySharabin
Copy link
Member

DmitrySharabin commented Mar 7, 2023

By the way, it would be nice if you could also make the corresponding changes to our testsuite so that it reflects the changes to the API. To be precise, to this file. But that's not necessary. I can do it too. 😀

@LeaVerou
Copy link
Member

LeaVerou commented Mar 7, 2023

By the way, it would be nice if you could also make the corresponding changes to our testsuite so that it reflects the changes to the API. To be precise, to this file. But that's not necessary. I can do it too. 😀

Actually, it's even more important to make the changes in our docs. (which should also include both versions, with e.g. groupBy just saying something like "Name of group_by() before v0.3.0", with a note about which Mavo version supports what)

@DmitrySharabin
Copy link
Member

DmitrySharabin commented Oct 6, 2023

@LeaVerou, it seems to me this PR is also worth merging before v0.3.0 is released. It will allow us to be consistent with the new functions (e.g., readable_datetime()). @norbitrial did a great job. There is a couple of minor issues left I can fix myself.

@netlify
Copy link

netlify bot commented Oct 6, 2023

Deploy Preview for getmavo ready!

Name Link
🔨 Latest commit 2e6e578
🔍 Latest deploy log https://app.netlify.com/sites/getmavo/deploys/6536bdfeee73e700072a864d
😎 Deploy Preview https://deploy-preview-821--getmavo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@mavoweb mavoweb deleted a comment from netlify bot Oct 6, 2023
Copy link
Member

@LeaVerou LeaVerou left a comment

Choose a reason for hiding this comment

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

LGTM, my only suggestion would be to abstract the deprecation code away into a function instead of repeating it.

Something like:

function deprecatedFunction(name, oldName, fn = _[name]) {
	return function (...args) {
		Mavo.warn(`${oldName}() is deprecated and will be removed in the next version of Mavo. Please use ${name}() instead.");
		return fn(...args);
	}
}

...and to make the docs and tests edits!

In fact, in https://mavo.io/docs/functions/ I think we should have two entries for each of these, with the old one saying "Deprecated alias of xxx()"

@DmitrySharabin
Copy link
Member

Done.

Copy link
Member

@LeaVerou LeaVerou left a comment

Choose a reason for hiding this comment

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

Can we not remove extra commas please?

a) trailing commas are there for a reason, it means that adding things after is less likely to result in a syntax error
b) even if we wanted to remove trailing commas, this PR is not the place and it increases the size of the diff making it harder to review

Also, this abstracted away the deprecation code, but is not using it in all three places where it's needed.
We should expose it somewhere, so that other modules can use it as well (or even plugins).

@DmitrySharabin
Copy link
Member

DmitrySharabin commented Oct 6, 2023

Can we not remove extra commas please?

Sorry about that. I thought they were some leftovers from a code formatter (e.g., Prettier). Fixed it.

Also, this abstracted away the deprecation code, but is not using it in all three places where it's needed. We should expose it somewhere, so that other modules can use it as well (or even plugins).

I hesitated to put it into utils.js and made the wrong choice. I should have asked. From my point of view, utils.js might be a good place for the deprecatedFunction() function. If not, I'm open to making other changes if needed.

@LeaVerou
Copy link
Member

LeaVerou commented Oct 7, 2023

Can we not remove extra commas please?

Sorry about that. I thought they were some leftovers from a code formatter (e.g., Prettier). Fixed it.

Also, this abstracted away the deprecation code, but is not using it in all three places where it's needed. We should expose it somewhere, so that other modules can use it as well (or even plugins).

I hesitated to put it into utils.js and made the wrong choice. I should have asked. From my point of view, utils.js might be a good place for the deprecatedFunction() function. If not, I'm open to making other changes if needed.

Yeah, I can't think of a better place either, so utils it is. Or Mavo.Script. Up to you!

@DmitrySharabin
Copy link
Member

Yeah, I can't think of a better place either, so utils it is. Or Mavo.Script. Up to you!

Then, I believe it's ready for your review. Again. 😅

@LeaVerou
Copy link
Member

LeaVerou commented Oct 7, 2023

Actually I know where it should live! On Mavo.Functions.util! Apologies, I forgot about that entirely.

@DmitrySharabin
Copy link
Member

Actually I know where it should live! On Mavo.Functions.util! Apologies, I forgot about that entirely.

Honestly, I was also trying to “house” deprecatedFunction() there (it was one of my first attempts). However, I faced an issue I didn't (and still don't) know how to resolve elegantly.

Suppose we have the following code (where $u is an alias for _.util):

fromlast: $u.deprecatedFunction("from_last", "fromlast")

And since util is defined below and we are trying to use something that is not yet defined, we get an error TypeError: Cannot read properties of undefined (reading 'util').

I suspect that we can do something like this (and it works)

fromlast: (...args) => $u.deprecatedFunction("from_last", "fromlast").call(this, ...args)

But I'm unsure whether it's the correct way to do this. What am I missing?

@LeaVerou
Copy link
Member

LeaVerou commented Oct 23, 2023

Actually I know where it should live! On Mavo.Functions.util! Apologies, I forgot about that entirely.

Honestly, I was also trying to “house” deprecatedFunction() there (it was one of my first attempts). However, I faced an issue I didn't (and still don't) know how to resolve elegantly.

Suppose we have the following code (where $u is an alias for _.util):

fromlast: $u.deprecatedFunction("from_last", "fromlast")

And since util is defined below and we are trying to use something that is not yet defined, we get an error TypeError: Cannot read properties of undefined (reading 'util').

I suspect that we can do something like this (and it works)

fromlast: (...args) => $u.deprecatedFunction("from_last", "fromlast").call(this, ...args)

But I'm unsure whether it's the correct way to do this. What am I missing?

Just move it up?

E.g.

let $u = {
	/* utils here */
};

Mavo.Functions = {
	/* ... */
	util: $u
}

@DmitrySharabin
Copy link
Member

Just move it up?

It worked! 🥳 Thank you.

@DmitrySharabin DmitrySharabin merged commit 1c9c152 into mavoweb:master Oct 24, 2023
4 checks passed
@DmitrySharabin
Copy link
Member

@norbitrial, thank you so much for your work!

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

3 participants