-
Notifications
You must be signed in to change notification settings - Fork 7k
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
Add a strip function to remove non-critical moment properties #1455
Comments
Instead of
Also worth noting: the expensiveness of parsingFlags only comes up when you actually parse a lot strings; cloning just copies the reference (shallow clone, which is totally right). |
Another use case to keep in mind, moment-timezone uses the |
Ah, that's a good point. It also puts a big hole in my idea in #1754 to just make clone explicitly copy the fields (which might be a good optimization for clone whether or not we do immutability); we don't know what fields defined in plugins need to be copied. |
In the latest version there is a way for plugins to add the fields they're adding to moment to the whitelist. Latest moment-timezone is doing that. Just edit The thing is I broke |
@ichernev Oh cool, that gives me a path back to my optimization idea. I can just remove items from Re: breaking plugins: we can just look through the ones on the docs and see if they fiddle with the moment object directly. I suspect most don't, since they're mostly about building, wrapping, or formatting moments, not altering their behavior like TZ does. |
I didn't quite get the optimization thing. |
Sorry, referencing other tickets. I'll explain with code and some perf tests. |
So, two years later now, I think there is quite a bit of code that relies on parsing flags and other variables being the way they are, and this change doesn't make sense. As such, I'm going to close this for the sake of cleaning house on issues. I'll assign a v3 milestone in case we want to find it down the road when considering total rewrite style scenarios. |
We've been adding properties to the moment object here and there and now most of them are used only at the parsing stage, revealing information about what exactly got parsed and how, but most users don't care and if you happen to have a big array of objects this also leads to higher memory footprint.
So lets add a function
moment.fn.strip()
, that would remove all unnecessary properties, and keep only:_isAMomentObject
,_isUTC
,_l
,_d
._offset
.The text was updated successfully, but these errors were encountered: