|
1 | 1 | import { setModifierManager, capabilities } from '@ember/modifier'; |
2 | | -import { untrack } from '@glimmer/validator'; |
| 2 | +import { |
| 3 | + macroCondition, |
| 4 | + dependencySatisfies, |
| 5 | + importSync, |
| 6 | +} from '@embroider/macros'; |
| 7 | + |
| 8 | +// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment |
| 9 | +const untrack: (fn: () => void) => void = (function () { |
| 10 | + if (macroCondition(dependencySatisfies('ember-source', '> 3.27.0-beta.1'))) { |
| 11 | + // ember-source@3.27 shipped "real modules" by default, so we can just use |
| 12 | + // importSync to get @glimmer/validator directly |
| 13 | + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-explicit-any |
| 14 | + const module = importSync('@glimmer/validator') as any; |
| 15 | + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access |
| 16 | + return module.untrack as unknown as (fn: () => void) => void; |
| 17 | + } else if ( |
| 18 | + macroCondition(dependencySatisfies('ember-source', '>= 3.22.0-alpha.1')) |
| 19 | + ) { |
| 20 | + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-explicit-any |
| 21 | + const module = importSync('ember') as any; |
| 22 | + // we can access `window.Ember` here because it wasn't deprecated until at least 3.27 |
| 23 | + // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access |
| 24 | + return module.__loader.require('@glimmer/validator').untrack; |
| 25 | + } else { |
| 26 | + // we do not call `untrack` when ember-source < 3.22 |
| 27 | + // (we don't suport ember-source < 3.22) |
| 28 | + } |
| 29 | +})(); |
3 | 30 |
|
4 | 31 | import type { |
5 | 32 | ModifierArgs, |
|
0 commit comments