Skip to content

Commit

Permalink
feat(modifier-managers): use 3.22 capabilities
Browse files Browse the repository at this point in the history
BREAKING CHANGE: destruction behavior changed to use new args proxy from
3.22

Resolves the issue
  described by: emberjs/ember.js#19162
  fixed by: emberjs/ember.js#19163
  • Loading branch information
NullVoxPopuli committed Oct 16, 2020
1 parent a8d4da7 commit 1f119e7
Show file tree
Hide file tree
Showing 7 changed files with 3,436 additions and 2,040 deletions.
32 changes: 15 additions & 17 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ language: node_js
node_js:
# we recommend testing addons with the same minimum supported node version as Ember CLI
# so that your addon works for all apps
- "10"
- "8"

dist: xenial
sudo: false
dist: trusty

addons:
chrome: stable
Expand All @@ -25,29 +26,30 @@ branches:
- /^v\d+\.\d+\.\d+/

jobs:
fast_finish: true
fail_fast: true
allow_failures:
- env: EMBER_TRY_SCENARIO=ember-canary
- env: EMBER_TRY_SCENARIO=typescript-next

include:
# runs linting and tests with current locked deps

- stage: "Tests"
name: "Tests"
install:
- yarn install --non-interactive
script:
- yarn lint
- yarn test:ember
- yarn lint:hbs
- yarn lint:js
- yarn test

- stage: "Additional Tests"
name: "Floating Dependencies"
install:
- yarn install --no-lockfile --non-interactive
- name: "Floating Dependencies"
script:
- yarn test:ember
- yarn test

# we recommend new addons test the current and previous LTS
# as well as latest stable release (bonus points to beta/canary)
- env: EMBER_TRY_SCENARIO=ember-lts-3.4
- stage: "Additional Tests"
env: EMBER_TRY_SCENARIO=ember-lts-3.4
- env: EMBER_TRY_SCENARIO=ember-lts-3.8
- env: EMBER_TRY_SCENARIO=ember-lts-3.12
- env: EMBER_TRY_SCENARIO=ember-lts-3.16
Expand All @@ -56,17 +58,13 @@ jobs:
- env: EMBER_TRY_SCENARIO=ember-beta
- env: EMBER_TRY_SCENARIO=ember-canary
- env: EMBER_TRY_SCENARIO=ember-default-with-jquery
- env: EMBER_TRY_SCENARIO=typescript-3.6
- env: EMBER_TRY_SCENARIO=typescript-3.7
- env: EMBER_TRY_SCENARIO=typescript-next
- env: EMBER_TRY_SCENARIO=ember-classic

before_install:
- curl -o- -L https://yarnpkg.com/install.sh | bash
- export PATH=$HOME/.yarn/bin:$PATH

install:
- yarn install --non-interactive
- yarn install --no-lockfile --non-interactive

script:
- node_modules/.bin/ember try:one $EMBER_TRY_SCENARIO
24 changes: 19 additions & 5 deletions addon/-private/class/modifier-manager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { capabilities } from '@ember/modifier';
import { gte } from 'ember-compatibility-helpers';
import { set } from '@ember/object';
import { destroy, registerDestructor } from '@ember/destroyable';

Expand All @@ -10,16 +11,30 @@ function destroyModifier(modifier: ClassBasedModifier): void {
modifier.willDestroy();
}

type CreateModifierArgs313 = [
{ owner: unknown; class: typeof ClassBasedModifier },
ModifierArgs
];
type CreateModifierArgs322 = [typeof ClassBasedModifier, ModifierArgs];
type CreateModifierArgs = CreateModifierArgs313 | CreateModifierArgs322;

export default class ClassBasedModifierManager {
capabilities = capabilities('3.13');
capabilities = capabilities(gte('3.22.0') ? '3.22' : '3.13');

constructor(private owner: unknown) {}

createModifier(
factory: { owner: unknown; class: typeof ClassBasedModifier },
args: ModifierArgs
...createModifierArgs: CreateModifierArgs
): ClassBasedModifier {
const Modifier = factory.class;
const [factoryOrClass, args] = createModifierArgs;

let Modifier: typeof ClassBasedModifier;

if ('owner' in factoryOrClass) {
Modifier = factoryOrClass.class;
} else {
Modifier = factoryOrClass;
}

const modifier = new Modifier(this.owner, args);

Expand All @@ -35,7 +50,6 @@ export default class ClassBasedModifierManager {
}

updateModifier(instance: ClassBasedModifier, args: ModifierArgs): void {
// TODO: this should be an args proxy
set(instance, 'args', args);
instance.didUpdateArguments();
instance.didReceiveArguments();
Expand Down
3 changes: 2 additions & 1 deletion addon/-private/functional/modifier-manager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { capabilities } from '@ember/modifier';
import { gte } from 'ember-compatibility-helpers';
import { FunctionalModifier } from './modifier';
import { ModifierArgs } from '../interfaces';

Expand Down Expand Up @@ -29,7 +30,7 @@ function setup(
}

class FunctionalModifierManager {
capabilities = capabilities('3.13');
capabilities = capabilities(gte('3.22.0') ? '3.22' : '3.13');

createModifier(factory: Factory): FunctionalModifier {
// This looks superfluous, but this is creating a new instance
Expand Down
54 changes: 26 additions & 28 deletions config/ember-try.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
'use strict';

const getChannelURL = require('ember-source-channel-url');
const typeTests = require('./ember-try-typescript');

const typeScriptScenarios = typeTests.scenarios.map((s) => ({
...s,
command: typeTests.command,
}));

module.exports = async function () {
module.exports = async function() {
return {
useYarn: true,
scenarios: [
{
name: 'ember-lts-2.18',
env: {
EMBER_OPTIONAL_FEATURES: JSON.stringify({
'jquery-integration': true,
}),
},
npm: {
devDependencies: {
'@ember/jquery': '^0.5.1',
'ember-source': '~2.18.0',
},
},
},
{
name: 'ember-lts-3.4',
npm: {
Expand All @@ -32,7 +40,7 @@ module.exports = async function () {
name: 'ember-lts-3.12',
npm: {
devDependencies: {
'ember-source': '~3.12.0',
'ember-source': '~3.16.0',
},
},
},
Expand Down Expand Up @@ -76,39 +84,29 @@ module.exports = async function () {
},
},
},
// The default `.travis.yml` runs this scenario via `yarn test`,
// not via `ember try`. It's still included here so that running
// `ember try:each` manually or from a customized CI config will run it
// along with all the other scenarios.
{
name: 'ember-default-with-jquery',
env: {
EMBER_OPTIONAL_FEATURES: JSON.stringify({
'jquery-integration': true,
}),
},
name: 'ember-default',
npm: {
devDependencies: {
'@ember/jquery': '^0.5.1',
},
devDependencies: {},
},
},
{
name: 'ember-classic',
name: 'ember-default-with-jquery',
env: {
EMBER_OPTIONAL_FEATURES: JSON.stringify({
'application-template-wrapper': true,
'default-async-observers': false,
'template-only-glimmer-components': false,
'jquery-integration': true,
}),
},
npm: {
ember: {
edition: 'classic',
devDependencies: {
'@ember/jquery': '^0.5.1',
},
},
},

// Include the type tests, while still leaving them in their own file so
// they can be run independently, for example to run all the type tests but
// *only* the type tests locally.
...typeScriptScenarios,
],
};
};
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
"ember-cli-normalize-entity-name": "^1.0.0",
"ember-cli-string-utils": "^1.1.0",
"ember-cli-typescript": "^3.1.3",
"ember-destroyable-polyfill": "^2.0.2",
"ember-modifier-manager-polyfill": "^1.2.0"
"ember-compatibility-helpers": "^1.2.1"
},
"devDependencies": {
"@ember/optional-features": "^1.3.0",
Expand All @@ -66,14 +65,13 @@
"ember-cli-sri": "^2.1.1",
"ember-cli-typescript-blueprints": "^3.0.0",
"ember-cli-uglify": "^3.0.0",
"ember-decorators-polyfill": "^1.0.6",
"ember-disable-prototype-extensions": "^1.1.3",
"ember-export-application-global": "^2.0.1",
"ember-load-initializers": "^2.1.1",
"ember-maybe-import-regenerator": "^0.1.6",
"ember-qunit": "^4.6.0",
"ember-resolver": "^8.0.0",
"ember-source": "~3.20.2",
"ember-source": "~3.22.0",
"ember-source-channel-url": "^2.0.1",
"ember-template-lint": "^2.9.1",
"ember-try": "^1.4.0",
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/modifiers/class-modifier-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,11 +472,11 @@ module('Integration | Modifier Manager | class-based modifier', function (
}

didReceiveArguments(): void {
callback('didReceiveArguments', this);
callback('didReceiveArguments', this, this.args.named.foo)
}

didUpdateArguments(): void {
callback('didUpdateArguments', this);
callback('didUpdateArguments', this, this.args.named.foo);
}

didInstall(): void {
Expand Down
Loading

0 comments on commit 1f119e7

Please sign in to comment.