cibernox / ember-power-calendar

Powerful and customizable calendar component for Ember
http://www.ember-power-calendar.com
Other
211 stars 118 forks source link

Embroider compatibility #210

Closed ef4 closed 9 months ago

ef4 commented 5 years ago

Opening this as a followup discussion to https://github.com/embroider-build/embroider/issues/134

I think the simplest path is to make the internal protocol between ember-power-calendar and its helper addons explicit.

For example, in ember-power-calendar-moment, we could have:

// app/initializers/ember-power-calendar-moment.js
import { registerDateLibrary } from 'ember-power-calendar';
import momentUtils from 'ember-power-calendar-moment';
export default {
  name: 'ember-power-calendar-moment',
  initialize() {
    registerDateLibrary(momentUtils);
  }
}

There is a fancier possible solution that uses @embroider/macros and would eliminate the need for separate ember-power-calendar-luxon and ember-power-calendar-moment packages, but I realized that it would need a thing from NPM that doesn't exist: optional peer dependencies. I'm hesitant to open that can of worms right now.

cibernox commented 5 years ago

IIRC, optional peer dependencies has been something a lot of people has been waiting for ages.

What would that registerDateLibrary do?

ef4 commented 5 years ago
// addon/index.js
let dateLib;
export function registerDateLibrary(d) {
  dateLib = d;
}
export function formatDate(d) {
  if (!dateLib) {
    throw new Error('ember-power-calendar needs ember-power-calendar-moment or ember-power-calendar-luxon');
  }
  return dateLib.formatDate(d);
}
// addon/helpers/power-calendar-format-date.js
-import { formatDate } from 'ember-power-calendar-utils';
+import { formatDate } from '..';
mkszepp commented 9 months ago

With the latest version (0.21.0) we have done change that the addon is fully embroider safe. The plan is also to bring this addon to a v2, when we have ember basic dropdown... ready for that