siddii / angular-timer

re-usable/inter-operable AngularJS timer directive ⛺
http://siddii.github.io/angular-timer/
MIT License
792 stars 939 forks source link

Gracefully fallback when no internationalization/duration features needed #168

Open siddii opened 9 years ago

siddii commented 9 years ago

We need to remove hard dependency on external scripts like moment, humanize duration etc.. We should gracefully fallback or warn if those features are requested/used without including those scripts.

siddii commented 9 years ago

@polomarcus - Let me know what you think of this issue.

polomarcus commented 9 years ago

Good idea, I will try to work on this soon.

polomarcus commented 9 years ago

Hi @siddii,

TL;DR : we should keep momentjs dependency at anytime and we can make humanize duration dependency optional

Why?

For MomentJS

If we do this, I can see 2 options :

I think we should not do this, but that's just my opinion:

For Humanize Duration

The variables secondUnit, minuteUnit etc. containing the translated duration will not be initialized when Humanize Duration is not available. This line will contain an if(humDurationHere) to initialize them or not https://github.com/siddii/angular-timer/blob/master/app/js/_timer.js#L205 FYI, The i18nService.js with Humanize Duration can be momentJS free. Pro :

Do not hesitate to discuss about this

siddii commented 9 years ago

@polomarcus - Thanks for the write-up!

I think the biggest thing I am trying to avoid here is not to have 3 installs (or script includes) (angular-timer, momentjs, humanize-duration) to start using this module. My understanding is that we can make HumanizeDuration optional(?) easily, whereas momentjs is not that straight forward.

OK, I'll throw out something & see what you think... How about we build a distribution script called angular-timer-all.js which includes all the dependencies (obviously checking if moment exists provide one, so as humanize duration etc.) and its up-to the developers to choose whether they want to pull just the angular-timer or not. In that way, we can have a simple integration rather than three different includes.

Let me know...

polomarcus commented 9 years ago

@siddii,

This solution would be great for people using manually downloads. We cannot have a choice between angular-timer-all.js and the other file when we use bower install angular-timer, don't we?

When doing a bower install, the users would still need to include the angular-timer, momentjs, humanize-duration scripts in their build.config.js for example. If we choose the "all" scripts in bower, the users won't be able to use their specific version of momentjs.

build.config.js example:

vendor_files: {
    js: [
      'vendor/angular/angular.min.js',
      'vendor/moment/min/moment-with-locales.min.js',
      'vendor/humanize-duration/humanize-duration.js',
      'vendor/angular-timer/dist/angular-timer.min.js',
    ]

The only affected files would be Gruntfile.js