-
-
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 canary]: Remove the last Symbols (#6428)
* [BUGIFX canary] Replace IS_IDENTIFIER Symbol.. ..by IDENTIFIERS WeakMap * [BUGFIX canary]: Switch Symbol to symbol * Relocate IDENTIFIERS * Add unmarkStableIdentifier() to remove.. identifier from the WeakMap when it is removed from the identifier cache. * [TESTS] Add cache integration test
- Loading branch information
Showing
4 changed files
with
75 additions
and
11 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
packages/-ember-data/tests/integration/identifiers/cache-test.ts
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,55 @@ | ||
import { module, test } from 'qunit'; | ||
import { setupTest } from 'ember-qunit'; | ||
import { IDENTIFIERS } from '@ember-data/canary-features'; | ||
import Store from '@ember-data/store'; | ||
import { identifierCacheFor } from '@ember-data/store/-private'; | ||
|
||
if (IDENTIFIERS) { | ||
module('Integration | Identifiers - cache', function(hooks) { | ||
setupTest(hooks); | ||
let store, cache; | ||
|
||
hooks.beforeEach(function() { | ||
this.owner.register(`service:store`, Store); | ||
store = this.owner.lookup('service:store'); | ||
cache = identifierCacheFor(store); | ||
}); | ||
|
||
module('getOrCreateRecordIdentifier()', function() { | ||
test('creates a new resource identifier if forgetRecordIdentifier() has been called on the existing identifier', async function(assert) { | ||
const runspiredHash = { | ||
type: 'person', | ||
id: '1', | ||
attributes: { | ||
name: 'runspired', | ||
}, | ||
}; | ||
const identifier = cache.getOrCreateRecordIdentifier(runspiredHash); | ||
|
||
cache.forgetRecordIdentifier(identifier); | ||
|
||
const regeneratedIdentifier = cache.getOrCreateRecordIdentifier(runspiredHash); | ||
|
||
assert.notEqual(identifier, regeneratedIdentifier, 'a record get a new identifier if identifier get forgotten'); | ||
}); | ||
|
||
test('returns the existing identifier when called with an identifier', async function(assert) { | ||
const houseHash = { | ||
type: 'house', | ||
id: '1', | ||
attributes: { | ||
name: 'Moomin', | ||
}, | ||
}; | ||
const cache = identifierCacheFor(store); | ||
const identifier = cache.getOrCreateRecordIdentifier(houseHash); | ||
|
||
assert.equal( | ||
identifier, | ||
cache.getOrCreateRecordIdentifier(identifier), | ||
'getOrCreateRecordIdentifier() return identifier' | ||
); | ||
}); | ||
}); | ||
}); | ||
} |
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
16 changes: 13 additions & 3 deletions
16
packages/store/addon/-private/identifiers/is-stable-identifier.ts
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,9 +1,19 @@ | ||
import { StableRecordIdentifier, IS_IDENTIFIER } from '../ts-interfaces/identifier'; | ||
import { StableRecordIdentifier } from '../ts-interfaces/identifier'; | ||
|
||
/** | ||
@module @ember-data/store | ||
*/ | ||
|
||
export default function isStableIdentifier(identifier: any): identifier is StableRecordIdentifier { | ||
return identifier[IS_IDENTIFIER] === true; | ||
const IDENTIFIERS = new WeakMap(); | ||
|
||
export default function isStableIdentifier(identifier: Object): identifier is StableRecordIdentifier { | ||
return IDENTIFIERS.has(identifier); | ||
} | ||
|
||
export function markStableIdentifier(identifier: Object) { | ||
IDENTIFIERS.set(identifier, 'is-identifier'); | ||
} | ||
|
||
export function unmarkStableIdentifier(identifier: Object) { | ||
IDENTIFIERS.delete(identifier); | ||
} |
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