-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BUGFIX] fix importing from @ember-data/store
Dividing Record Data into packages (#6513) configured the Store class inside of the `-ember-data` metapackage. This broke importing the Store directly from `@ember-data/store`, which this commit fixes.
- Loading branch information
Showing
3 changed files
with
99 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1 @@ | ||
import { IDENTIFIERS } from '@ember-data/canary-features'; | ||
import { RecordData } from '@ember-data/record-data/-private'; | ||
import Store from '@ember-data/store'; | ||
import { identifierCacheFor } from '@ember-data/store/-private'; | ||
|
||
type RecordDataStoreWrapper = import('@ember-data/store/-private/ts-interfaces/record-data-store-wrapper').RecordDataStoreWrapper; | ||
|
||
export default class DefaultStore extends Store { | ||
createRecordDataFor(modelName: string, id: string | null, clientId: string, storeWrapper: RecordDataStoreWrapper) { | ||
if (IDENTIFIERS) { | ||
let identifier = identifierCacheFor(this).getOrCreateRecordIdentifier({ | ||
type: modelName, | ||
id, | ||
lid: clientId, | ||
}); | ||
return new RecordData(identifier, storeWrapper); | ||
} else { | ||
return new RecordData(modelName, id, clientId, storeWrapper); | ||
} | ||
} | ||
} | ||
export { default } from '@ember-data/store'; |
70 changes: 70 additions & 0 deletions
70
packages/-ember-data/tests/integration/store/package-import-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { get } from '@ember/object'; | ||
import { settled } from '@ember/test-helpers'; | ||
|
||
import { module, test } from 'qunit'; | ||
|
||
import { setupTest } from 'ember-qunit'; | ||
|
||
import Model, { attr } from '@ember-data/model'; | ||
import Store from '@ember-data/store'; | ||
|
||
class Person extends Model { | ||
@attr() | ||
name; | ||
} | ||
|
||
class CustomStore extends Store {} | ||
|
||
module('integration/store/package-import', function(hooks) { | ||
setupTest(hooks); | ||
|
||
let store; | ||
|
||
hooks.beforeEach(function() { | ||
let { owner } = this; | ||
|
||
owner.register('model:person', Person); | ||
owner.unregister('service:store'); | ||
owner.register('service:store', CustomStore); | ||
store = owner.lookup('service:store'); | ||
}); | ||
|
||
test('Store push works with an import from @ember-data/store', async function(assert) { | ||
store.push({ | ||
data: [ | ||
{ | ||
type: 'person', | ||
id: '1', | ||
attributes: { | ||
name: 'Scumbag Dale', | ||
}, | ||
}, | ||
{ | ||
type: 'person', | ||
id: '2', | ||
attributes: { | ||
name: 'Scumbag Katz', | ||
}, | ||
}, | ||
], | ||
}); | ||
|
||
let all = store.peekAll('person'); | ||
assert.equal(get(all, 'length'), 2); | ||
|
||
store.push({ | ||
data: [ | ||
{ | ||
type: 'person', | ||
id: '3', | ||
attributes: { | ||
name: 'Scumbag Bryn', | ||
}, | ||
}, | ||
], | ||
}); | ||
|
||
await settled(); | ||
assert.equal(get(all, 'length'), 3); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters