Skip to content

Commit

Permalink
Interop with EmberObject.extend on < 3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
chancancode committed Sep 19, 2019
1 parent 02c66d3 commit 3696183
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
50 changes: 50 additions & 0 deletions tests/integration/components/modifier-manager-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -74,6 +75,55 @@ module('Integration | Component | modifier-manager', function(hooks) {

await render(hbs`<div {{my-modifier}}></div>`);
});


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`<div {{my-modifier}}></div>`);
});

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`<div {{my-modifier}}></div>`);
});
});

module('installModifier', function(hooks) {
Expand Down
8 changes: 7 additions & 1 deletion vendor/ember-modifier-manager-polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 3696183

Please sign in to comment.