WhoopInc / frozen-moment-OLD

NOW A MOMENT PLUGIN:
https://github.com/WhoopInc/frozen-moment
MIT License
9 stars 0 forks source link

Make the default locale immutable at runtime #10

Open butterflyhug opened 10 years ago

butterflyhug commented 10 years ago

Up to now, we've been copying Moment's forward-looking locale API.

That Moment API has a setter and getter for a global locale setting. These can be used to change the behavior of the parsing functions at any time, and Moment instances can be bound to this global setting so that their locale changes whenever the global setting changes.

Thing is, the very idea of having global state that's changeable at runtime is a very poor fit for a library where immutability is the primary selling point. As a result, we will be sharply curtailing the scope of FrozenMoment's global locale setting.

Our revised API will focus on enabling developers to configure a non-English default locale for all new FrozenMoments created in a particular runtime environment. (A runtime environment is a web page in the browser, or a Node application.) Applications that need to change locales at runtime should always set the locale on their FrozenMoment instances, and/or override each instance's locale setting for each formatting operation.

Here's a minimal set of required API changes:

(This follows up on observations from PR #9, as part of my continued work on issue #2.)