Skip to content

Commit

Permalink
[BUGFIX release] Ensure component creation issues deprecation for tra…
Browse files Browse the repository at this point in the history
…cked property mutation
  • Loading branch information
rwjblue committed Nov 19, 2020
1 parent ab92dea commit 6f00b74
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Factory } from '@ember/-internals/owner';
import { assert } from '@ember/debug';
import { DEBUG } from '@glimmer/env';
import {
Arguments,
ComponentCapabilities,
Expand All @@ -24,6 +25,7 @@ import {
buildCapabilities,
registerDestructor,
} from '@glimmer/runtime';
import { deprecateMutationsInTrackingTransaction } from '@glimmer/validator';
import { argsProxyFor } from '../utils/args-proxy';

const CAPABILITIES = {
Expand Down Expand Up @@ -136,11 +138,19 @@ export default class CustomComponentManager<ComponentInstance>
let { delegate } = definition;
let args = argsProxyFor(vmArgs.capture(), 'component');

let component = delegate.createComponent(definition.ComponentClass.class!, args);
let component;

if (DEBUG && deprecateMutationsInTrackingTransaction !== undefined) {
deprecateMutationsInTrackingTransaction(() => {
component = delegate.createComponent(definition.ComponentClass.class!, args);
});
} else {
component = delegate.createComponent(definition.ComponentClass.class!, args);
}

let bucket = new CustomComponentState(delegate, component, args, env);

return bucket;
return bucket as CustomComponentState<ComponentInstance>;
}

getDebugName({ name }: CustomComponentDefinitionState<ComponentInstance>): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { DEBUG } from '@glimmer/env';
import { moduleFor, RenderingTestCase, runTask, strip } from 'internal-test-helpers';

import { Object as EmberObject } from '@ember/-internals/runtime';
import { set, setProperties, computed } from '@ember/-internals/metal';
import { set, setProperties, computed, tracked } from '@ember/-internals/metal';
import { setComponentManager, capabilities } from '@ember/-internals/glimmer';

const BasicComponentManager = EmberObject.extend({
Expand Down Expand Up @@ -897,5 +897,35 @@ moduleFor(

assert.verifySteps([]);
}

'@test tracked property mutation in constructor issues a deprecation'() {
let ComponentClass = setComponentManager(
createBasicManager,
class extends EmberObject {
@tracked itemCount = 0;

init() {
super.init(...arguments);

// first read the tracked property
let { itemCount } = this;

// then attempt to update the tracked property
this.itemCount = itemCount + 1;
}
}
);

this.registerComponent('foo-bar', {
template: `{{this.itemCount}}`,
ComponentClass,
});

expectDeprecation(() => {
this.render('<FooBar />');
}, /asdf/);

this.assertHTML(`1`);
}
}
);

0 comments on commit 6f00b74

Please sign in to comment.