@@ -4,7 +4,9 @@ var nodeLists = require('can-view-nodelist');
4
4
var makeFrag = require ( 'can-fragment' ) ;
5
5
var childNodes = require ( 'can-child-nodes' ) ;
6
6
var canReflect = require ( 'can-reflect' ) ;
7
+ var canSymbol = require ( "can-symbol" ) ;
7
8
var queues = require ( "can-queues" ) ;
9
+ var viewInsertSymbol = canSymbol . for ( "can.viewInsert" ) ;
8
10
9
11
10
12
function updateNodeList ( oldNodes , nodes , frag , nodeListUpdatedByFn ) {
@@ -48,10 +50,22 @@ function updateNodeList(oldNodes, nodes, frag, nodeListUpdatedByFn) {
48
50
*
49
51
*
50
52
*/
51
- live . html = function ( el , compute , parentNode , nodeList ) {
52
- var data ,
53
- makeAndPut ,
54
- nodes ;
53
+ live . html = function ( el , compute , parentNode , nodeListOrOptions ) {
54
+ var data ;
55
+ var makeAndPut ;
56
+ var nodeList ;
57
+ var nodes ;
58
+ var options ;
59
+
60
+ // nodeListOrOptions can either be a NodeList or an object with a nodeList property
61
+ if ( nodeListOrOptions !== undefined ) {
62
+ if ( Array . isArray ( nodeListOrOptions ) ) {
63
+ nodeList = nodeListOrOptions ;
64
+ } else {
65
+ nodeList = nodeListOrOptions . nodeList ;
66
+ options = nodeListOrOptions ;
67
+ }
68
+ }
55
69
56
70
var meta = { reasonLog : "live.html replace::" + canReflect . getName ( compute ) } ;
57
71
// prefer to manipulate el's actual parent over the supplied parent
@@ -79,7 +93,7 @@ live.html = function(el, compute, parentNode, nodeList) {
79
93
} ;
80
94
}
81
95
} ) ;
82
-
96
+
83
97
Object . defineProperty ( liveHTMLUpdateHTML , "name" , {
84
98
value : "live.html update::" + canReflect . getName ( compute ) ,
85
99
} ) ;
@@ -93,10 +107,18 @@ live.html = function(el, compute, parentNode, nodeList) {
93
107
nodes = nodeList || [ el ] ;
94
108
makeAndPut = function ( val , useQueue ) {
95
109
// ##### makeandput
96
- // Receives the compute output (must be some DOM representation or a function)
97
- var isFunction = typeof val === "function" ,
98
- // translate val into a document fragment if it's DOM-like
99
- frag = makeFrag ( isFunction ? "" : val ) ;
110
+ // Receives the compute output (must be some DOM representation, a function,
111
+ // or an object with the can.viewInsert symbol)
112
+
113
+ // If val has the can.viewInsert symbol, call it and get something usable for val back
114
+ if ( val && typeof val [ viewInsertSymbol ] === "function" ) {
115
+ val = val [ viewInsertSymbol ] ( options ) ;
116
+ }
117
+
118
+ var isFunction = typeof val === "function" ;
119
+
120
+ // translate val into a document fragment if it's DOM-like
121
+ var frag = makeFrag ( isFunction ? "" : val ) ;
100
122
101
123
// Add a placeholder textNode if necessary.
102
124
live . addTextNodeIfNoChildren ( frag ) ;
0 commit comments