mirror of
https://github.com/google/blockly.git
synced 2026-01-07 00:50:27 +01:00
feat: allow duplicate registry values (#7988)
This commit is contained in:
committed by
GitHub
parent
5a6f22f0f3
commit
6767717d0b
@@ -162,8 +162,13 @@ export function register<T>(
|
||||
// Validate that the given class has all the required properties.
|
||||
validate(type, registryItem);
|
||||
|
||||
// Don't throw an error if opt_allowOverrides is true.
|
||||
if (!opt_allowOverrides && typeRegistry[caselessName]) {
|
||||
// Don't throw an error if opt_allowOverrides is true,
|
||||
// or if we're trying to register the same item.
|
||||
if (
|
||||
!opt_allowOverrides &&
|
||||
typeRegistry[caselessName] &&
|
||||
typeRegistry[caselessName] !== registryItem
|
||||
) {
|
||||
throw Error(
|
||||
'Name "' +
|
||||
caselessName +
|
||||
|
||||
@@ -47,6 +47,15 @@ suite('Registry', function () {
|
||||
test('Overwrite a Key', function () {
|
||||
Blockly.registry.register('test', 'test_name', TestClass);
|
||||
chai.assert.throws(function () {
|
||||
// Registers a different object under the same name
|
||||
Blockly.registry.register('test', 'test_name', {});
|
||||
}, 'already registered');
|
||||
});
|
||||
|
||||
test('Register a Duplicate Item', function () {
|
||||
Blockly.registry.register('test', 'test_name', TestClass);
|
||||
chai.assert.doesNotThrow(function () {
|
||||
// Registering the same object under the same name is allowed
|
||||
Blockly.registry.register('test', 'test_name', TestClass);
|
||||
}, 'already registered');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user