Skip to content

Commit

Permalink
Component defaultLoader should use hasOwnProperty for isRegistered check
Browse files Browse the repository at this point in the history
  • Loading branch information
rniemeyer committed Apr 8, 2015
1 parent 1768108 commit 04596e8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 8 additions & 0 deletions spec/components/defaultLoaderBehaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ describe('Components: Default loader', function() {
expect(ko.components.isRegistered(testComponentName)).toBe(false);
});

it('Allows registering component names that may conflict with properties on Object.prototype', function() {
var prototypeProperty = 'toString';

expect(ko.components.isRegistered(prototypeProperty)).toBe(false);
ko.components.register(prototypeProperty, {});
expect(ko.components.isRegistered(prototypeProperty)).toBe(true);
});

it('Throws if you try to register a component that is already registered', function() {
ko.components.register(testComponentName, {});

Expand Down
8 changes: 4 additions & 4 deletions src/components/defaultLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@
}

defaultConfigRegistry[componentName] = config;
}
};

ko.components.isRegistered = function(componentName) {
return componentName in defaultConfigRegistry;
}
return defaultConfigRegistry.hasOwnProperty(componentName);
};

ko.components.unregister = function(componentName) {
delete defaultConfigRegistry[componentName];
ko.components.clearCachedDefinition(componentName);
}
};

ko.components.defaultLoader = {
'getConfig': function(componentName, callback) {
Expand Down

0 comments on commit 04596e8

Please sign in to comment.