From 3696183874b3e44887d17593ada7547abfecdd80 Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Wed, 18 Sep 2019 22:18:53 -0700 Subject: [PATCH] Interop with EmberObject.extend on < 3.1 --- .../components/modifier-manager-test.js | 50 +++++++++++++++++++ vendor/ember-modifier-manager-polyfill.js | 8 ++- 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/tests/integration/components/modifier-manager-test.js b/tests/integration/components/modifier-manager-test.js index b63b636..2386903 100644 --- a/tests/integration/components/modifier-manager-test.js +++ b/tests/integration/components/modifier-manager-test.js @@ -2,6 +2,7 @@ import { module, test } from 'qunit'; import { setupRenderingTest } from 'ember-qunit'; import { render } from '@ember/test-helpers'; import hbs from 'htmlbars-inline-precompile'; +import EmberObject from '@ember/object'; import { assign } from '@ember/polyfills'; import { capabilities, setModifierManager } from '@ember/modifier'; @@ -74,6 +75,55 @@ module('Integration | Component | modifier-manager', function(hooks) { await render(hbs`
`); }); + + + test('it can find the manager set on a native super-class', async function(assert) { + assert.expect(1); + + class BaseModifier {} + class MyModifier extends BaseModifier {} + + this.owner.register('modifier:my-modifier', MyModifier); + + setModifierManager( + () => ({ + capabilities: capabilities('3.13'), + createModifier(factory) { + assert.equal(factory.class, MyModifier, 'the factory class is Modifier'); + }, + installModifier() {}, + updateModifier() {}, + destroyModifier() {}, + }), + BaseModifier + ); + + await render(hbs`
`); + }); + + test('it can find the manager set on a EmberObject super-class', async function(assert) { + assert.expect(1); + + const BaseModifier = EmberObject.extend({}); + const MyModifier = BaseModifier.extend({}); + + this.owner.register('modifier:my-modifier', MyModifier); + + setModifierManager( + () => ({ + capabilities: capabilities('3.13'), + createModifier(factory) { + assert.equal(factory.class, MyModifier, 'the factory class is Modifier'); + }, + installModifier() {}, + updateModifier() {}, + destroyModifier() {}, + }), + BaseModifier + ); + + await render(hbs`
`); + }); }); module('installModifier', function(hooks) { diff --git a/vendor/ember-modifier-manager-polyfill.js b/vendor/ember-modifier-manager-polyfill.js index dd57de7..d0049cd 100644 --- a/vendor/ember-modifier-manager-polyfill.js +++ b/vendor/ember-modifier-manager-polyfill.js @@ -22,7 +22,13 @@ import { deprecate } from '@ember/debug'; return MODIFIER_MANAGERS.get(pointer); } - pointer = getPrototypeOf(pointer); + if (gte('3.1.0-beta.1')) { + pointer = getPrototypeOf(pointer); + } else if (Ember.Object.detect(pointer) && typeof pointer.superclass === 'function') { + pointer = pointer.superclass; + } else { + pointer = getPrototypeOf(pointer); + } } return;