Skip to content

Commit

Permalink
Merge pull request #59 from canjs/2-use-default-noop
Browse files Browse the repository at this point in the history
Use default noop function for unregistered tags.
  • Loading branch information
Macrofig authored Sep 29, 2017
2 parents 7077bec + 17e8b95 commit df54039
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion can-view-callbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ var attr = function (attributeName, attrHandler) {
var attributes = {},
regExpAttributes = [],
automaticCustomElementCharacters = /[-\:]/;
var defaultCallback = function () {};

var tag = function (tagName, tagHandler) {
if(tagHandler) {
Expand Down Expand Up @@ -82,7 +83,7 @@ var tag = function (tagName, tagHandler) {

if(!cb && automaticCustomElementCharacters.test(tagName)) {
// empty callback for things that look like special tags
cb = function(){};
cb = defaultCallback;
}
return cb;
}
Expand All @@ -94,6 +95,7 @@ var callbacks = {
_tags: tags,
_attributes: attributes,
_regExpAttributes: regExpAttributes,
defaultCallback: defaultCallback,
tag: tag,
attr: attr,
// handles calling back a tag callback
Expand Down
8 changes: 8 additions & 0 deletions test/callbacks-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,12 @@ if (System.env.indexOf('production') < 0) {
// callback attr provided
callbacks.attr(attrMatch, function(){});
});

QUnit.test("tag method should return default callback when valid tag but not registered", function () {
equal(callbacks.tag('not-exist'), callbacks.defaultCallback, "used default noop function")
});

QUnit.test("tag method should return undefined when invalid tag and not registered", function () {
notOk(callbacks.tag('notexist'), "used default noop function")
});
}

0 comments on commit df54039

Please sign in to comment.