Skip to content

Commit

Permalink
fix creation recursion with ember-data-model-fragments (#7123)
Browse files Browse the repository at this point in the history
  • Loading branch information
BryanCrotaz authored and runspired committed Apr 24, 2020
1 parent bf1afa4 commit 387fc3e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { module, test } from 'qunit';

import { setupTest } from 'ember-qunit';

import Transform from '@ember-data/serializer/transform';

module('integration/store/creation-recursion', function(hooks) {
setupTest(hooks);

test('store construction does not construct transforms', function(assert) {
let storeFactory = this.owner.factoryFor('service:store');

this.owner.unregister('service:store');
this.owner.register('service:store', storeFactory);

let test = this;
test.dateTransformCreated = false;
class MockDateTransform extends Transform {
constructor(...args) {
super(...args);
test.dateTransformCreated = true;
}
}

this.owner.unregister('transform:date');
this.owner.register('transform:date', MockDateTransform);

assert.notOk(this.dateTransformCreated, 'date transform is not yet created');

// construct a store - it should now be created
this.owner.lookup('service:store');

assert.notOk(this.dateTransformCreated, 'date transform is not yet created');

// construct a date transform - it should now be created
this.owner.lookup('transform:date');

assert.ok(this.dateTransformCreated, 'date transform is now created');
});
});
7 changes: 4 additions & 3 deletions packages/store/addon/-private/system/core-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,15 +333,16 @@ abstract class CoreStore extends Service {
};
let shouldWarn = false;

let owner = getOwner(this);
Object.keys(Mapping).forEach((attributeType: keyof typeof Mapping) => {
const transform = getOwner(this).lookup(`transform:${attributeType}`);
const transformFactory = owner.factoryFor(`transform:${attributeType}`);

if (!transform) {
if (!transformFactory) {
// we don't deprecate this because the moduleFor style tests with the closed
// resolver will be deprecated on their own. When that deprecation completes
// we can drop this.
const Transform = require(`@ember-data/serializer/-private`)[Mapping[attributeType]];
getOwner(this).register(`transform:${attributeType}`, Transform);
owner.register(`transform:${attributeType}`, Transform);
shouldWarn = true;
}
});
Expand Down

0 comments on commit 387fc3e

Please sign in to comment.