Skip to content

Commit

Permalink
Merge pull request #73 from canjs/nl
Browse files Browse the repository at this point in the history
Pass nodeList through when there is a subtemplate and the tag returns.
  • Loading branch information
matthewp authored Jan 3, 2018
2 parents dc14a8c + 1d7b59e commit bfdc566
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 15 deletions.
12 changes: 9 additions & 3 deletions can-view-callbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ var dev = require('can-log/dev/dev');
var getGlobal = require('can-globals/global/global');
var domMutate = require('can-dom-mutate/node');
var namespace = require('can-namespace');
var nodeLists = require('can-view-nodelist');
var makeFrag = require("can-util/dom/frag/frag");

//!steal-remove-start
var requestedAttributes = {};
Expand Down Expand Up @@ -123,7 +125,7 @@ var callbacks = {
var ceConstructor = GLOBAL.document.createElement(tagName).constructor;
// If not registered as a custom element, the browser will use default constructors
if (ceConstructor === GLOBAL.HTMLElement || ceConstructor === GLOBAL.HTMLUnknownElement) {
dev.warn('can-view-callbacks: No custom element found for ' + tagName);
dev.warn('can-view-callbacks: No custom element found for ' + tagName);
}
}
//!steal-remove-end
Expand All @@ -135,8 +137,12 @@ var callbacks = {
if (scope !== res) {
scope = scope.add(res);
}
var result = tagData.subtemplate(scope, tagData.options);
var frag = typeof result === "string" ? can.view.frag(result) : result;

var nodeList = nodeLists.register([], undefined, tagData.parentNodeList || true, false);
nodeList.expression = "<" + el.tagName + ">";

var result = tagData.subtemplate(scope, tagData.options, nodeList);
var frag = typeof result === "string" ? makeFrag(result) : result;
domMutate.appendChild.call(el, frag);
}
}
Expand Down
13 changes: 4 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"release:minor": "npm version minor && npm publish",
"release:major": "npm version major && npm publish",
"build": "node build.js",
"develop": "done-serve --static --develop --port 8080",
"detect-cycle": "detect-cyclic-packages --ignore done-serve"
},
"main": "can-view-callbacks",
Expand All @@ -32,18 +31,14 @@
"canjs-plugin",
"donejs"
],
"steal": {
"configDependencies": [
"live-reload"
]
},
"dependencies": {
"can-dom-mutate": "<2.0.0",
"can-globals": "^0.3.0",
"can-log": "^0.1.2",
"can-globals": "<2.0.0",
"can-log": "<2.0.0",
"can-namespace": "1.0.0",
"can-observation-recorder": "<2.0.0",
"can-util": "^3.9.5"
"can-util": "^3.9.5",
"can-view-nodelist": "^4.0.0-pre.5"
},
"devDependencies": {
"can-test-helpers": "^1.0.1",
Expand Down
29 changes: 26 additions & 3 deletions test/callbacks-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var QUnit = require('steal-qunit');
var callbacks = require('can-view-callbacks');
var nodeLists = require('can-view-nodelist');
var dev = require('can-log/dev/dev');
var can = require('can-namespace');
var clone = require('steal-clone');
Expand Down Expand Up @@ -120,7 +121,7 @@ if (System.env.indexOf('production') < 0) {
QUnit.test("should return callback (#60)", function(){
var handler = function() {};
callbacks.attr('foo', handler);

var fooHandler = callbacks.attr('foo');
equal(fooHandler, handler, 'registered handler returned');
});
Expand All @@ -131,15 +132,15 @@ if(document.registerElement) {
var restore = devUtils.willWarn(/no custom element found for/i);
testTagHandler(customElement);
equal(restore(), 1);
});
});

devUtils.devOnlyTest("should not warn about defined custom elements (#56)", function(){
document.registerElement('custom-element', {});
var customElement = document.createElement('custom-element');
var restore = devUtils.willWarn(/no custom element found for/i);
testTagHandler(customElement);
equal(restore(), 0);
});
});
}

function testTagHandler(customElement){
Expand Down Expand Up @@ -167,3 +168,25 @@ QUnit.test("can read tags from templateContext.tags", function() {
scope: scope
});
});

QUnit.test("Passes through nodeList", function(){
QUnit.expect(2);

var nodeList = nodeLists.register([], null, true, false);

var scope = new Scope({});

callbacks.tag("nodelist-tag", function(){
return {};
});
var el = document.createElement("div");
callbacks.tagHandler(el, "nodelist-tag", {
scope: scope,
parentNodeList: nodeList,
subtemplate: function(scope, helpers, localNodeList){
QUnit.ok(localNodeList, "nodeList was provided");
QUnit.equal(localNodeList.parentList, nodeList, "it is our provided nodeList");
return "<div></div>";
}
});
});

0 comments on commit bfdc566

Please sign in to comment.