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

Runtime: Fix unitFormatter with numberFormatter #719

Closed

Conversation

nkovacs
Copy link
Contributor

@nkovacs nkovacs commented May 11, 2017

JSON.stringify omits functions, so the generated runtimeKey
did not depend on the value of the numberFormatter option,
causing different unitFormatters to have an identical runtimeKey.

Fixes #704

fn.runtimeKey = key;
}
return fn;
};
Copy link
Member

Choose a reason for hiding this comment

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

Oh! For your proposed solution, we need this function that is similar to common/runtime-bind.js. Can you move this into its own file in common/ and update usage to look like this please (i.e., use a function directly instead of Globalize.)?

PS: It will be challenging to find a name to distinguish this from runtime-bind. Feel free to rename the latter to accommodate a good naming for both.

Copy link
Member

Choose a reason for hiding this comment

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

Thinking more about it...

Instead of stamping the functions in here, we could do that in the compiler itself (during build time).

Copy link
Contributor Author

@nkovacs nkovacs May 11, 2017

Choose a reason for hiding this comment

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

I wanted to avoid having to change the compiler, since it's a separate package.
People would get broken builds if they only update globalize, not the compiler.

Copy link
Member

Choose a reason for hiding this comment

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

The goal is to make the runtime code (this code) leaner, which is optimal. No worries about updating the compiler. I can help feel you if you have any questions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, but how can you force a project using globalize and globalize-compiler to update the compiler when globalize is updated? If only globalize is updated, it will generate a different runtime key during compilation, and the runtime bundle won't find the correct function.

Copy link
Member

Choose a reason for hiding this comment

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

We cannot force, indeed, but there are ways to bring this information to the projects. One is documentation and release notes. Another is to use semver and make the existing globalize-compiler to require a peer globalize that goes up until 1.2.3; Only new globalize-compiler will support a peer globalize 1.3.0.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, fortunately, globalize-compiler currently has a peer dependency on globalize <1.3.0, so that'll get people to upgrade the compiler as well.

Copy link
Member

Choose a reason for hiding this comment

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

👍

@rxaviers
Copy link
Member

Thanks @nkovacs!! Great catch!

I left a comment above. What do you think? Just let me know if you have any questions about it...

@nkovacs nkovacs force-pushed the 704-unitformatter-runtimekey branch from d8f9ece to caa45b8 Compare May 11, 2017 14:49
return function( args ) {
return JSON.stringify( args, function( key, value ) {
if ( typeof value === "function" ) {
return value.runtimeKey; // if undefined, the value will be filtered out.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if we should do something about functions that don't have a runtimeKey.

@nkovacs
Copy link
Contributor Author

nkovacs commented May 11, 2017

Pull request for compiler is up: globalizejs/globalize-compiler#31
and I've removed the hack in core-runtime.js.

JSON.stringify omits functions, so the generated runtimeKey
did not depend on the value of the numberFormatter option,
causing different unitFormatters to have an identical runtimeKey.

Fixes globalizejs#704
@nkovacs nkovacs force-pushed the 704-unitformatter-runtimekey branch from caa45b8 to c85af7c Compare May 22, 2017 11:09
@nkovacs
Copy link
Contributor Author

nkovacs commented May 22, 2017

I've rebased on master and uncommented the compiler test. Travis fails because of the missing compiler change.

@rxaviers
Copy link
Member

Ok thanks

@rxaviers
Copy link
Member

@nkovacs, other formatters (e.g., date, relative time) also include a number formatter in their runtime properties. We need to understand why this happens with unit formatter, but not with the other ones...

@nkovacs
Copy link
Contributor Author

nkovacs commented May 22, 2017

No other formatter accepts a formatter as an option which should affect the runtimeKey.

@rxaviers
Copy link
Member

True! Thanks

@rxaviers rxaviers added this to the 1.3.0 milestone May 29, 2017
@rxaviers rxaviers modified the milestones: 1.3.0, 1.4.0 Jun 15, 2017
@rxaviers rxaviers closed this in 0d31631 Jul 13, 2018
rxaviers added a commit that referenced this pull request Jul 13, 2018
rxaviers added a commit that referenced this pull request Jul 13, 2018
@rxaviers
Copy link
Member

Thanks @nkovacs!

Pull request for compiler is up: globalizejs/globalize-compiler#31
and I've removed the hack in core-runtime.js.

Instead of depending on globalize-compiler to include the runtimeKey info, I've update the runtime function to do it.

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