From 8fbb94de54ed1d51a9eb7cbdc55e77d32c8d08d4 Mon Sep 17 00:00:00 2001 From: Bajix Date: Wed, 14 Dec 2016 21:19:00 -0800 Subject: [PATCH 1/5] Upgrade StealJS --- package.json | 16 ++++++++-------- src/template.js | 4 ++-- src/template.txt | 10 +++++----- test/build.js | 2 +- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index c0a69c9..ff1fea3 100644 --- a/package.json +++ b/package.json @@ -26,17 +26,17 @@ "can-component": "^3.0.3", "can-list": "^3.0.1", "can-map": "^3.0.3", - "can-map-define": "^3.0.1", + "can-map-define": "^3.0.2", "can-route": "^3.0.5", "funcunit": "^3.1.0", "lodash.template": "^4.4.0", - "steal": "^0.16.43", - "steal-qunit": "0.1.4", - "steal-tools": "^0.16.8", + "steal": "^1.0.3", + "steal-qunit": "1.0.0", + "steal-tools": "^1.0.1", "testee": "^0.3.0" }, "homepage": "https://github.com/donejs/autorender", - "system": { + "steal": { "npmAlgorithm": "flat", "directories": { "lib": "src" @@ -44,11 +44,11 @@ }, "dependencies": { "can-route": "^3.0.5", - "can-stache": "^3.0.13", - "can-util": "^3.0.13", + "can-stache": "^3.0.15", + "can-util": "^3.1.0", "can-view-import": "^3.0.3", "can-view-model": "^3.1.2", "can-zone": "^0.6.0", - "steal-stache": "^3.0.3" + "steal-stache": "^3.0.4" } } diff --git a/src/template.js b/src/template.js index e78a14f..2c66a15 100644 --- a/src/template.js +++ b/src/template.js @@ -9,9 +9,9 @@ __p += 'define(' + ((__t = ( args )) == null ? '' : __t) + '){\n\n var tokens = ' + ((__t = ( intermediate )) == null ? '' : __t) + -';\n\n var renderer = stache(tokens);\n\n var isNode = typeof process === "object" && {}.toString.call(process) === "[object process]";\n\n // SSR helpers isProduction, and some that don\'t matter in the client.\n stache.registerHelper("isProduction", function(options){\n var loader = typeof System !== "undefined" ? System : undefined;\n if(loader && loader.isEnv && loader.isEnv("production")) {\n return options.fn(this);\n } else {\n return options.inverse(this);\n }\n });\n\n function systemImportZone(){\n var oldImport;\n var myImport = function(){\n return Promise.resolve(oldImport.apply(this, arguments));\n };\n return {\n beforeTask: function(){\n oldImport = System.import;\n System.import = myImport;\n },\n afterTask: function(){\n System.import = oldImport;\n }\n };\n }\n\n var slice = Array.prototype.slice;\n function makeArray(parent) {\n return slice.call(childNodes(parent));\n }\n\n var autorender = {\n renderToFrag: function(scope, options){\n var moduleOptions = { module: module };\n options = (options && options.add) ? options.add(moduleOptions) :\n moduleOptions;\n return renderer(scope, options);\n },\n start: function(){\n var autorender = this;\n new Zone({\n plugins: [xhrZone, systemImportZone]\n }).run(function(){\n var state = autorender.state = new autorender.viewModel;\n\n var docEl = document.documentElement;\n domData.set.call(docEl, "viewModel", state);\n\n route.map(state);\n route.ready();\n\n autorender.rerender();\n });\n },\n rerender: function(){\n var keep = { "SCRIPT": true, "STYLE": true, "LINK": true };\n function eachChild(parent, callback){\n var nodes = makeArray(parent), node;\n var i = 0, len = nodes.length;\n\n for(; i < len; i++) {\n node = nodes[i];\n if(!keep[node.nodeName]) {\n if(callback(node) === false) {\n break;\n }\n }\n }\n }\n\n function remove(el) {\n mutate.removeChild.call(el.parentNode, el);\n }\n\n function appendTo(parent){\n return function(el){\n mutate.appendChild.call(parent, el);\n }\n }\n\n function traverse(node, tagName){\n var child;\n eachChild(node, function(el){\n if(el.tagName === tagName) {\n child = el;\n return false;\n } else {\n child = traverse(el, tagName);\n return !child;\n }\n });\n return child;\n }\n\n this.renderAsync().then(function(result){\n var frag = result.fragment;\n var head = document.head || document.getElementsByTagName("head")[0];\n var body = document.body;\n\n // Move elements from the fragment\'s head to the document head.\n eachChild(head, remove);\n\n var fragHead = traverse(frag, "HEAD");\n eachChild(fragHead, appendTo(head));\n\n // Move elements from the fragment\'s body to the document body.\n eachChild(body, remove);\n\n var fragBody = traverse(frag, "BODY");\n eachChild(fragBody, appendTo(body));\n });\n },\n renderAsync: function(renderer, data, options, doc){\n renderer = renderer || this.renderToFrag;\n data = data || this.state;\n options = options || {};\n\n var frag;\n\n var zone = new Zone({\n plugins: [xhrZone, systemImportZone]\n });\n\n return zone.run(function(){\n frag = renderer(data, options);\n\n if(doc) {\n var oldDoc = can.document;\n can.document = doc;\n mutate.appendChild.call(doc.body, frag, doc);\n can.document = oldDoc;\n }\n }).then(function(zoneData){\n return {\n fragment: frag,\n zoneData: zoneData\n };\n });\n },\n legacy: false,\n render: function(doc, state){\n var renderer = this.renderToFrag;\n var frag = renderer(state, {});\n\n var oldDoc = can.document;\n can.document = doc;\n mutate.appendChild.call(doc.body, frag, doc);\n can.document = oldDoc;\n },\n ' + +';\n\n var renderer = stache(tokens);\n\n var isNode = typeof process === "object" && {}.toString.call(process) === "[object process]";\n\n // SSR helpers isProduction, and some that don\'t matter in the client.\n stache.registerHelper("isProduction", function(options){\n var loader = typeof steal !== "undefined" ? steal : undefined;\n if(loader && loader.isEnv && loader.isEnv("production")) {\n return options.fn(this);\n } else {\n return options.inverse(this);\n }\n });\n\n function systemImportZone(){\n var oldImport;\n var myImport = function(){\n return Promise.resolve(oldImport.apply(this, arguments));\n };\n return {\n beforeTask: function(){\n oldImport = steal.import;\n steal.import = myImport;\n },\n afterTask: function(){\n steal.import = oldImport;\n }\n };\n }\n\n var slice = Array.prototype.slice;\n function makeArray(parent) {\n return slice.call(childNodes(parent));\n }\n\n var autorender = {\n renderToFrag: function(scope, options){\n var moduleOptions = { module: module };\n options = (options && options.add) ? options.add(moduleOptions) :\n moduleOptions;\n return renderer(scope, options);\n },\n start: function(){\n var autorender = this;\n new Zone({\n plugins: [xhrZone, systemImportZone]\n }).run(function(){\n var state = autorender.state = new autorender.viewModel;\n\n var docEl = document.documentElement;\n domData.set.call(docEl, "viewModel", state);\n\n route.map(state);\n route.ready();\n\n autorender.rerender();\n });\n },\n rerender: function(){\n var keep = { "SCRIPT": true, "STYLE": true, "LINK": true };\n function eachChild(parent, callback){\n var nodes = makeArray(parent), node;\n var i = 0, len = nodes.length;\n\n for(; i < len; i++) {\n node = nodes[i];\n if(!keep[node.nodeName]) {\n if(callback(node) === false) {\n break;\n }\n }\n }\n }\n\n function remove(el) {\n mutate.removeChild.call(el.parentNode, el);\n }\n\n function appendTo(parent){\n return function(el){\n mutate.appendChild.call(parent, el);\n }\n }\n\n function traverse(node, tagName){\n var child;\n eachChild(node, function(el){\n if(el.tagName === tagName) {\n child = el;\n return false;\n } else {\n child = traverse(el, tagName);\n return !child;\n }\n });\n return child;\n }\n\n this.renderAsync().then(function(result){\n var frag = result.fragment;\n var head = document.head || document.getElementsByTagName("head")[0];\n var body = document.body;\n\n // Move elements from the fragment\'s head to the document head.\n eachChild(head, remove);\n\n var fragHead = traverse(frag, "HEAD");\n eachChild(fragHead, appendTo(head));\n\n // Move elements from the fragment\'s body to the document body.\n eachChild(body, remove);\n\n var fragBody = traverse(frag, "BODY");\n eachChild(fragBody, appendTo(body));\n });\n },\n renderAsync: function(renderer, data, options, doc){\n renderer = renderer || this.renderToFrag;\n data = data || this.state;\n options = options || {};\n\n var frag;\n\n var zone = new Zone({\n plugins: [xhrZone, systemImportZone]\n });\n\n return zone.run(function(){\n frag = renderer(data, options);\n\n if(doc) {\n var oldDoc = can.document;\n can.document = doc;\n mutate.appendChild.call(doc.body, frag, doc);\n can.document = oldDoc;\n }\n }).then(function(zoneData){\n return {\n fragment: frag,\n zoneData: zoneData\n };\n });\n },\n legacy: false,\n render: function(doc, state){\n var renderer = this.renderToFrag;\n var frag = renderer(state, {});\n\n var oldDoc = can.document;\n can.document = doc;\n mutate.appendChild.call(doc.body, frag, doc);\n can.document = oldDoc;\n },\n ' + ((__t = ( ases )) == null ? '' : __t) + -'\n };\n var isNW = (function(){\n try{var nr = System._nodeRequire; return nr && nr(\'nw.gui\') !== \'undefined\';}catch(e){return false;}\n })();\n\n if(typeof steal !== \'undefined\' && (isNW || !isNode))\n steal.done().then(function() {\n if(steal.System.autorenderAutostart !== false) {\n autorender.start();\n }\n });\n\n return autorender;\n});\n'; +'\n };\n var isNW = (function(){\n try{var nr = steal._nodeRequire; return nr && nr(\'nw.gui\') !== \'undefined\';}catch(e){return false;}\n })();\n\n if(typeof steal !== \'undefined\' && (isNW || !isNode))\n steal.done().then(function() {\n if(steal.System.autorenderAutostart !== false) {\n autorender.start();\n }\n });\n\n return autorender;\n});\n'; } return __p diff --git a/src/template.txt b/src/template.txt index 8d1b96e..61ef217 100644 --- a/src/template.txt +++ b/src/template.txt @@ -8,7 +8,7 @@ define(<%= imports %>, function(<%= args %>){ // SSR helpers isProduction, and some that don't matter in the client. stache.registerHelper("isProduction", function(options){ - var loader = typeof System !== "undefined" ? System : undefined; + var loader = typeof steal !== "undefined" ? steal : undefined; if(loader && loader.isEnv && loader.isEnv("production")) { return options.fn(this); } else { @@ -23,11 +23,11 @@ define(<%= imports %>, function(<%= args %>){ }; return { beforeTask: function(){ - oldImport = System.import; - System.import = myImport; + oldImport = steal.import; + steal.import = myImport; }, afterTask: function(){ - System.import = oldImport; + steal.import = oldImport; } }; } @@ -158,7 +158,7 @@ define(<%= imports %>, function(<%= args %>){ <%= ases %> }; var isNW = (function(){ - try{var nr = System._nodeRequire; return nr && nr('nw.gui') !== 'undefined';}catch(e){return false;} + try{var nr = steal._nodeRequire; return nr && nr('nw.gui') !== 'undefined';}catch(e){return false;} })(); if(typeof steal !== 'undefined' && (isNW || !isNode)) diff --git a/test/build.js b/test/build.js index 7e9c521..4aca6a3 100644 --- a/test/build.js +++ b/test/build.js @@ -3,7 +3,7 @@ var stealTools = require("steal-tools"); stealTools.build({ config: __dirname + "/../package.json!npm", main: "test/basics/index.stache!done-autorender", - bundlesPath: "test/basics/dist/bundles" }, { + dest: "test/basics/dist", quiet: true }); From 23e7ad4f529c4b1b94f1ceb07ec36905263ab2b6 Mon Sep 17 00:00:00 2001 From: Bajix Date: Thu, 15 Dec 2016 15:44:02 -0800 Subject: [PATCH 2/5] Set route.data instead of using route.map(state) --- src/template.js | 2 +- src/template.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/template.js b/src/template.js index 2c66a15..fc89900 100644 --- a/src/template.js +++ b/src/template.js @@ -9,7 +9,7 @@ __p += 'define(' + ((__t = ( args )) == null ? '' : __t) + '){\n\n var tokens = ' + ((__t = ( intermediate )) == null ? '' : __t) + -';\n\n var renderer = stache(tokens);\n\n var isNode = typeof process === "object" && {}.toString.call(process) === "[object process]";\n\n // SSR helpers isProduction, and some that don\'t matter in the client.\n stache.registerHelper("isProduction", function(options){\n var loader = typeof steal !== "undefined" ? steal : undefined;\n if(loader && loader.isEnv && loader.isEnv("production")) {\n return options.fn(this);\n } else {\n return options.inverse(this);\n }\n });\n\n function systemImportZone(){\n var oldImport;\n var myImport = function(){\n return Promise.resolve(oldImport.apply(this, arguments));\n };\n return {\n beforeTask: function(){\n oldImport = steal.import;\n steal.import = myImport;\n },\n afterTask: function(){\n steal.import = oldImport;\n }\n };\n }\n\n var slice = Array.prototype.slice;\n function makeArray(parent) {\n return slice.call(childNodes(parent));\n }\n\n var autorender = {\n renderToFrag: function(scope, options){\n var moduleOptions = { module: module };\n options = (options && options.add) ? options.add(moduleOptions) :\n moduleOptions;\n return renderer(scope, options);\n },\n start: function(){\n var autorender = this;\n new Zone({\n plugins: [xhrZone, systemImportZone]\n }).run(function(){\n var state = autorender.state = new autorender.viewModel;\n\n var docEl = document.documentElement;\n domData.set.call(docEl, "viewModel", state);\n\n route.map(state);\n route.ready();\n\n autorender.rerender();\n });\n },\n rerender: function(){\n var keep = { "SCRIPT": true, "STYLE": true, "LINK": true };\n function eachChild(parent, callback){\n var nodes = makeArray(parent), node;\n var i = 0, len = nodes.length;\n\n for(; i < len; i++) {\n node = nodes[i];\n if(!keep[node.nodeName]) {\n if(callback(node) === false) {\n break;\n }\n }\n }\n }\n\n function remove(el) {\n mutate.removeChild.call(el.parentNode, el);\n }\n\n function appendTo(parent){\n return function(el){\n mutate.appendChild.call(parent, el);\n }\n }\n\n function traverse(node, tagName){\n var child;\n eachChild(node, function(el){\n if(el.tagName === tagName) {\n child = el;\n return false;\n } else {\n child = traverse(el, tagName);\n return !child;\n }\n });\n return child;\n }\n\n this.renderAsync().then(function(result){\n var frag = result.fragment;\n var head = document.head || document.getElementsByTagName("head")[0];\n var body = document.body;\n\n // Move elements from the fragment\'s head to the document head.\n eachChild(head, remove);\n\n var fragHead = traverse(frag, "HEAD");\n eachChild(fragHead, appendTo(head));\n\n // Move elements from the fragment\'s body to the document body.\n eachChild(body, remove);\n\n var fragBody = traverse(frag, "BODY");\n eachChild(fragBody, appendTo(body));\n });\n },\n renderAsync: function(renderer, data, options, doc){\n renderer = renderer || this.renderToFrag;\n data = data || this.state;\n options = options || {};\n\n var frag;\n\n var zone = new Zone({\n plugins: [xhrZone, systemImportZone]\n });\n\n return zone.run(function(){\n frag = renderer(data, options);\n\n if(doc) {\n var oldDoc = can.document;\n can.document = doc;\n mutate.appendChild.call(doc.body, frag, doc);\n can.document = oldDoc;\n }\n }).then(function(zoneData){\n return {\n fragment: frag,\n zoneData: zoneData\n };\n });\n },\n legacy: false,\n render: function(doc, state){\n var renderer = this.renderToFrag;\n var frag = renderer(state, {});\n\n var oldDoc = can.document;\n can.document = doc;\n mutate.appendChild.call(doc.body, frag, doc);\n can.document = oldDoc;\n },\n ' + +';\n\n var renderer = stache(tokens);\n\n var isNode = typeof process === "object" && {}.toString.call(process) === "[object process]";\n\n // SSR helpers isProduction, and some that don\'t matter in the client.\n stache.registerHelper("isProduction", function(options){\n var loader = typeof steal !== "undefined" ? steal : undefined;\n if(loader && loader.isEnv && loader.isEnv("production")) {\n return options.fn(this);\n } else {\n return options.inverse(this);\n }\n });\n\n function systemImportZone(){\n var oldImport;\n var myImport = function(){\n return Promise.resolve(oldImport.apply(this, arguments));\n };\n return {\n beforeTask: function(){\n oldImport = steal.import;\n steal.import = myImport;\n },\n afterTask: function(){\n steal.import = oldImport;\n }\n };\n }\n\n var slice = Array.prototype.slice;\n function makeArray(parent) {\n return slice.call(childNodes(parent));\n }\n\n var autorender = {\n renderToFrag: function(scope, options){\n var moduleOptions = { module: module };\n options = (options && options.add) ? options.add(moduleOptions) :\n moduleOptions;\n return renderer(scope, options);\n },\n start: function(){\n var autorender = this;\n new Zone({\n plugins: [xhrZone, systemImportZone]\n }).run(function(){\n var state = autorender.state = new autorender.viewModel;\n\n var docEl = document.documentElement;\n domData.set.call(docEl, "viewModel", state);\n\n route.data = state;\n route.ready();\n\n autorender.rerender();\n });\n },\n rerender: function(){\n var keep = { "SCRIPT": true, "STYLE": true, "LINK": true };\n function eachChild(parent, callback){\n var nodes = makeArray(parent), node;\n var i = 0, len = nodes.length;\n\n for(; i < len; i++) {\n node = nodes[i];\n if(!keep[node.nodeName]) {\n if(callback(node) === false) {\n break;\n }\n }\n }\n }\n\n function remove(el) {\n mutate.removeChild.call(el.parentNode, el);\n }\n\n function appendTo(parent){\n return function(el){\n mutate.appendChild.call(parent, el);\n }\n }\n\n function traverse(node, tagName){\n var child;\n eachChild(node, function(el){\n if(el.tagName === tagName) {\n child = el;\n return false;\n } else {\n child = traverse(el, tagName);\n return !child;\n }\n });\n return child;\n }\n\n this.renderAsync().then(function(result){\n var frag = result.fragment;\n var head = document.head || document.getElementsByTagName("head")[0];\n var body = document.body;\n\n // Move elements from the fragment\'s head to the document head.\n eachChild(head, remove);\n\n var fragHead = traverse(frag, "HEAD");\n eachChild(fragHead, appendTo(head));\n\n // Move elements from the fragment\'s body to the document body.\n eachChild(body, remove);\n\n var fragBody = traverse(frag, "BODY");\n eachChild(fragBody, appendTo(body));\n });\n },\n renderAsync: function(renderer, data, options, doc){\n renderer = renderer || this.renderToFrag;\n data = data || this.state;\n options = options || {};\n\n var frag;\n\n var zone = new Zone({\n plugins: [xhrZone, systemImportZone]\n });\n\n return zone.run(function(){\n frag = renderer(data, options);\n\n if(doc) {\n var oldDoc = can.document;\n can.document = doc;\n mutate.appendChild.call(doc.body, frag, doc);\n can.document = oldDoc;\n }\n }).then(function(zoneData){\n return {\n fragment: frag,\n zoneData: zoneData\n };\n });\n },\n legacy: false,\n render: function(doc, state){\n var renderer = this.renderToFrag;\n var frag = renderer(state, {});\n\n var oldDoc = can.document;\n can.document = doc;\n mutate.appendChild.call(doc.body, frag, doc);\n can.document = oldDoc;\n },\n ' + ((__t = ( ases )) == null ? '' : __t) + '\n };\n var isNW = (function(){\n try{var nr = steal._nodeRequire; return nr && nr(\'nw.gui\') !== \'undefined\';}catch(e){return false;}\n })();\n\n if(typeof steal !== \'undefined\' && (isNW || !isNode))\n steal.done().then(function() {\n if(steal.System.autorenderAutostart !== false) {\n autorender.start();\n }\n });\n\n return autorender;\n});\n'; diff --git a/src/template.txt b/src/template.txt index 61ef217..8af76d0 100644 --- a/src/template.txt +++ b/src/template.txt @@ -54,7 +54,7 @@ define(<%= imports %>, function(<%= args %>){ var docEl = document.documentElement; domData.set.call(docEl, "viewModel", state); - route.map(state); + route.data = state; route.ready(); autorender.rerender(); From a6bbf009bc512088ca6c535de2c89bc4e8d2283d Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Fri, 16 Dec 2016 13:06:53 -0500 Subject: [PATCH 3/5] Use a newer version of Firefox --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 106f2b0..bfadf8e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,8 @@ language: node_js node_js: 5.8 script: npm test +addons: + firefox: "48.0" before_install: - "export DISPLAY=:99.0" - "sh -e /etc/init.d/xvfb start" From 2feff0bccf217fb8d5600a4b6a846bbadddacccf Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Fri, 16 Dec 2016 13:09:51 -0500 Subject: [PATCH 4/5] Update template to use System --- src/template.js | 4 ++-- src/template.txt | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/template.js b/src/template.js index fc89900..10ce373 100644 --- a/src/template.js +++ b/src/template.js @@ -9,9 +9,9 @@ __p += 'define(' + ((__t = ( args )) == null ? '' : __t) + '){\n\n var tokens = ' + ((__t = ( intermediate )) == null ? '' : __t) + -';\n\n var renderer = stache(tokens);\n\n var isNode = typeof process === "object" && {}.toString.call(process) === "[object process]";\n\n // SSR helpers isProduction, and some that don\'t matter in the client.\n stache.registerHelper("isProduction", function(options){\n var loader = typeof steal !== "undefined" ? steal : undefined;\n if(loader && loader.isEnv && loader.isEnv("production")) {\n return options.fn(this);\n } else {\n return options.inverse(this);\n }\n });\n\n function systemImportZone(){\n var oldImport;\n var myImport = function(){\n return Promise.resolve(oldImport.apply(this, arguments));\n };\n return {\n beforeTask: function(){\n oldImport = steal.import;\n steal.import = myImport;\n },\n afterTask: function(){\n steal.import = oldImport;\n }\n };\n }\n\n var slice = Array.prototype.slice;\n function makeArray(parent) {\n return slice.call(childNodes(parent));\n }\n\n var autorender = {\n renderToFrag: function(scope, options){\n var moduleOptions = { module: module };\n options = (options && options.add) ? options.add(moduleOptions) :\n moduleOptions;\n return renderer(scope, options);\n },\n start: function(){\n var autorender = this;\n new Zone({\n plugins: [xhrZone, systemImportZone]\n }).run(function(){\n var state = autorender.state = new autorender.viewModel;\n\n var docEl = document.documentElement;\n domData.set.call(docEl, "viewModel", state);\n\n route.data = state;\n route.ready();\n\n autorender.rerender();\n });\n },\n rerender: function(){\n var keep = { "SCRIPT": true, "STYLE": true, "LINK": true };\n function eachChild(parent, callback){\n var nodes = makeArray(parent), node;\n var i = 0, len = nodes.length;\n\n for(; i < len; i++) {\n node = nodes[i];\n if(!keep[node.nodeName]) {\n if(callback(node) === false) {\n break;\n }\n }\n }\n }\n\n function remove(el) {\n mutate.removeChild.call(el.parentNode, el);\n }\n\n function appendTo(parent){\n return function(el){\n mutate.appendChild.call(parent, el);\n }\n }\n\n function traverse(node, tagName){\n var child;\n eachChild(node, function(el){\n if(el.tagName === tagName) {\n child = el;\n return false;\n } else {\n child = traverse(el, tagName);\n return !child;\n }\n });\n return child;\n }\n\n this.renderAsync().then(function(result){\n var frag = result.fragment;\n var head = document.head || document.getElementsByTagName("head")[0];\n var body = document.body;\n\n // Move elements from the fragment\'s head to the document head.\n eachChild(head, remove);\n\n var fragHead = traverse(frag, "HEAD");\n eachChild(fragHead, appendTo(head));\n\n // Move elements from the fragment\'s body to the document body.\n eachChild(body, remove);\n\n var fragBody = traverse(frag, "BODY");\n eachChild(fragBody, appendTo(body));\n });\n },\n renderAsync: function(renderer, data, options, doc){\n renderer = renderer || this.renderToFrag;\n data = data || this.state;\n options = options || {};\n\n var frag;\n\n var zone = new Zone({\n plugins: [xhrZone, systemImportZone]\n });\n\n return zone.run(function(){\n frag = renderer(data, options);\n\n if(doc) {\n var oldDoc = can.document;\n can.document = doc;\n mutate.appendChild.call(doc.body, frag, doc);\n can.document = oldDoc;\n }\n }).then(function(zoneData){\n return {\n fragment: frag,\n zoneData: zoneData\n };\n });\n },\n legacy: false,\n render: function(doc, state){\n var renderer = this.renderToFrag;\n var frag = renderer(state, {});\n\n var oldDoc = can.document;\n can.document = doc;\n mutate.appendChild.call(doc.body, frag, doc);\n can.document = oldDoc;\n },\n ' + +';\n\n var renderer = stache(tokens);\n\n var isNode = typeof process === "object" && {}.toString.call(process) === "[object process]";\n\n // SSR helpers isProduction, and some that don\'t matter in the client.\n stache.registerHelper("isProduction", function(options){\n var loader = typeof System !== "undefined" ? System : undefined;\n if(loader && loader.isEnv && loader.isEnv("production")) {\n return options.fn(this);\n } else {\n return options.inverse(this);\n }\n });\n\n function systemImportZone(){\n var oldImport;\n var myImport = function(){\n return Promise.resolve(oldImport.apply(this, arguments));\n };\n return {\n beforeTask: function(){\n oldImport = System.import;\n System.import = myImport;\n },\n afterTask: function(){\n System.import = oldImport;\n }\n };\n }\n\n var slice = Array.prototype.slice;\n function makeArray(parent) {\n return slice.call(childNodes(parent));\n }\n\n var autorender = {\n renderToFrag: function(scope, options){\n var moduleOptions = { module: module };\n options = (options && options.add) ? options.add(moduleOptions) :\n moduleOptions;\n return renderer(scope, options);\n },\n start: function(){\n var autorender = this;\n new Zone({\n plugins: [xhrZone, systemImportZone]\n }).run(function(){\n var state = autorender.state = new autorender.viewModel;\n\n var docEl = document.documentElement;\n domData.set.call(docEl, "viewModel", state);\n\n route.data = state;\n route.ready();\n\n autorender.rerender();\n });\n },\n rerender: function(){\n var keep = { "SCRIPT": true, "STYLE": true, "LINK": true };\n function eachChild(parent, callback){\n var nodes = makeArray(parent), node;\n var i = 0, len = nodes.length;\n\n for(; i < len; i++) {\n node = nodes[i];\n if(!keep[node.nodeName]) {\n if(callback(node) === false) {\n break;\n }\n }\n }\n }\n\n function remove(el) {\n mutate.removeChild.call(el.parentNode, el);\n }\n\n function appendTo(parent){\n return function(el){\n mutate.appendChild.call(parent, el);\n }\n }\n\n function traverse(node, tagName){\n var child;\n eachChild(node, function(el){\n if(el.tagName === tagName) {\n child = el;\n return false;\n } else {\n child = traverse(el, tagName);\n return !child;\n }\n });\n return child;\n }\n\n this.renderAsync().then(function(result){\n var frag = result.fragment;\n var head = document.head || document.getElementsByTagName("head")[0];\n var body = document.body;\n\n // Move elements from the fragment\'s head to the document head.\n eachChild(head, remove);\n\n var fragHead = traverse(frag, "HEAD");\n eachChild(fragHead, appendTo(head));\n\n // Move elements from the fragment\'s body to the document body.\n eachChild(body, remove);\n\n var fragBody = traverse(frag, "BODY");\n eachChild(fragBody, appendTo(body));\n });\n },\n renderAsync: function(renderer, data, options, doc){\n renderer = renderer || this.renderToFrag;\n data = data || this.state;\n options = options || {};\n\n var frag;\n\n var zone = new Zone({\n plugins: [xhrZone, systemImportZone]\n });\n\n return zone.run(function(){\n frag = renderer(data, options);\n\n if(doc) {\n var oldDoc = can.document;\n can.document = doc;\n mutate.appendChild.call(doc.body, frag, doc);\n can.document = oldDoc;\n }\n }).then(function(zoneData){\n return {\n fragment: frag,\n zoneData: zoneData\n };\n });\n },\n legacy: false,\n render: function(doc, state){\n var renderer = this.renderToFrag;\n var frag = renderer(state, {});\n\n var oldDoc = can.document;\n can.document = doc;\n mutate.appendChild.call(doc.body, frag, doc);\n can.document = oldDoc;\n },\n ' + ((__t = ( ases )) == null ? '' : __t) + -'\n };\n var isNW = (function(){\n try{var nr = steal._nodeRequire; return nr && nr(\'nw.gui\') !== \'undefined\';}catch(e){return false;}\n })();\n\n if(typeof steal !== \'undefined\' && (isNW || !isNode))\n steal.done().then(function() {\n if(steal.System.autorenderAutostart !== false) {\n autorender.start();\n }\n });\n\n return autorender;\n});\n'; +'\n };\n var isNW = (function(){\n try{var nr = System._nodeRequire; return nr && nr(\'nw.gui\') !== \'undefined\';}catch(e){return false;}\n })();\n\n if(typeof steal !== \'undefined\' && (isNW || !isNode))\n steal.done().then(function() {\n if(steal.System.autorenderAutostart !== false) {\n autorender.start();\n }\n });\n\n return autorender;\n});\n'; } return __p diff --git a/src/template.txt b/src/template.txt index 8af76d0..4370b05 100644 --- a/src/template.txt +++ b/src/template.txt @@ -8,7 +8,7 @@ define(<%= imports %>, function(<%= args %>){ // SSR helpers isProduction, and some that don't matter in the client. stache.registerHelper("isProduction", function(options){ - var loader = typeof steal !== "undefined" ? steal : undefined; + var loader = typeof System !== "undefined" ? System : undefined; if(loader && loader.isEnv && loader.isEnv("production")) { return options.fn(this); } else { @@ -23,11 +23,11 @@ define(<%= imports %>, function(<%= args %>){ }; return { beforeTask: function(){ - oldImport = steal.import; - steal.import = myImport; + oldImport = System.import; + System.import = myImport; }, afterTask: function(){ - steal.import = oldImport; + System.import = oldImport; } }; } @@ -158,7 +158,7 @@ define(<%= imports %>, function(<%= args %>){ <%= ases %> }; var isNW = (function(){ - try{var nr = steal._nodeRequire; return nr && nr('nw.gui') !== 'undefined';}catch(e){return false;} + try{var nr = System._nodeRequire; return nr && nr('nw.gui') !== 'undefined';}catch(e){return false;} })(); if(typeof steal !== 'undefined' && (isNW || !isNode)) From 4e6de006f2fb3131da27d2e71ae936b4823ba6c2 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Fri, 16 Dec 2016 15:24:00 -0500 Subject: [PATCH 5/5] Fix canViewModel test --- src/template.js | 2 +- src/template.txt | 1 - test/autorender_test.js | 2 +- test/basics/test.html | 14 +++++++++++--- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/template.js b/src/template.js index 10ce373..aba7447 100644 --- a/src/template.js +++ b/src/template.js @@ -9,7 +9,7 @@ __p += 'define(' + ((__t = ( args )) == null ? '' : __t) + '){\n\n var tokens = ' + ((__t = ( intermediate )) == null ? '' : __t) + -';\n\n var renderer = stache(tokens);\n\n var isNode = typeof process === "object" && {}.toString.call(process) === "[object process]";\n\n // SSR helpers isProduction, and some that don\'t matter in the client.\n stache.registerHelper("isProduction", function(options){\n var loader = typeof System !== "undefined" ? System : undefined;\n if(loader && loader.isEnv && loader.isEnv("production")) {\n return options.fn(this);\n } else {\n return options.inverse(this);\n }\n });\n\n function systemImportZone(){\n var oldImport;\n var myImport = function(){\n return Promise.resolve(oldImport.apply(this, arguments));\n };\n return {\n beforeTask: function(){\n oldImport = System.import;\n System.import = myImport;\n },\n afterTask: function(){\n System.import = oldImport;\n }\n };\n }\n\n var slice = Array.prototype.slice;\n function makeArray(parent) {\n return slice.call(childNodes(parent));\n }\n\n var autorender = {\n renderToFrag: function(scope, options){\n var moduleOptions = { module: module };\n options = (options && options.add) ? options.add(moduleOptions) :\n moduleOptions;\n return renderer(scope, options);\n },\n start: function(){\n var autorender = this;\n new Zone({\n plugins: [xhrZone, systemImportZone]\n }).run(function(){\n var state = autorender.state = new autorender.viewModel;\n\n var docEl = document.documentElement;\n domData.set.call(docEl, "viewModel", state);\n\n route.data = state;\n route.ready();\n\n autorender.rerender();\n });\n },\n rerender: function(){\n var keep = { "SCRIPT": true, "STYLE": true, "LINK": true };\n function eachChild(parent, callback){\n var nodes = makeArray(parent), node;\n var i = 0, len = nodes.length;\n\n for(; i < len; i++) {\n node = nodes[i];\n if(!keep[node.nodeName]) {\n if(callback(node) === false) {\n break;\n }\n }\n }\n }\n\n function remove(el) {\n mutate.removeChild.call(el.parentNode, el);\n }\n\n function appendTo(parent){\n return function(el){\n mutate.appendChild.call(parent, el);\n }\n }\n\n function traverse(node, tagName){\n var child;\n eachChild(node, function(el){\n if(el.tagName === tagName) {\n child = el;\n return false;\n } else {\n child = traverse(el, tagName);\n return !child;\n }\n });\n return child;\n }\n\n this.renderAsync().then(function(result){\n var frag = result.fragment;\n var head = document.head || document.getElementsByTagName("head")[0];\n var body = document.body;\n\n // Move elements from the fragment\'s head to the document head.\n eachChild(head, remove);\n\n var fragHead = traverse(frag, "HEAD");\n eachChild(fragHead, appendTo(head));\n\n // Move elements from the fragment\'s body to the document body.\n eachChild(body, remove);\n\n var fragBody = traverse(frag, "BODY");\n eachChild(fragBody, appendTo(body));\n });\n },\n renderAsync: function(renderer, data, options, doc){\n renderer = renderer || this.renderToFrag;\n data = data || this.state;\n options = options || {};\n\n var frag;\n\n var zone = new Zone({\n plugins: [xhrZone, systemImportZone]\n });\n\n return zone.run(function(){\n frag = renderer(data, options);\n\n if(doc) {\n var oldDoc = can.document;\n can.document = doc;\n mutate.appendChild.call(doc.body, frag, doc);\n can.document = oldDoc;\n }\n }).then(function(zoneData){\n return {\n fragment: frag,\n zoneData: zoneData\n };\n });\n },\n legacy: false,\n render: function(doc, state){\n var renderer = this.renderToFrag;\n var frag = renderer(state, {});\n\n var oldDoc = can.document;\n can.document = doc;\n mutate.appendChild.call(doc.body, frag, doc);\n can.document = oldDoc;\n },\n ' + +';\n\n var renderer = stache(tokens);\n\n var isNode = typeof process === "object" && {}.toString.call(process) === "[object process]";\n\n // SSR helpers isProduction, and some that don\'t matter in the client.\n stache.registerHelper("isProduction", function(options){\n var loader = typeof System !== "undefined" ? System : undefined;\n if(loader && loader.isEnv && loader.isEnv("production")) {\n return options.fn(this);\n } else {\n return options.inverse(this);\n }\n });\n\n function systemImportZone(){\n var oldImport;\n var myImport = function(){\n return Promise.resolve(oldImport.apply(this, arguments));\n };\n return {\n beforeTask: function(){\n oldImport = System.import;\n System.import = myImport;\n },\n afterTask: function(){\n System.import = oldImport;\n }\n };\n }\n\n var slice = Array.prototype.slice;\n function makeArray(parent) {\n return slice.call(childNodes(parent));\n }\n\n var autorender = {\n renderToFrag: function(scope, options){\n var moduleOptions = { module: module };\n options = (options && options.add) ? options.add(moduleOptions) :\n moduleOptions;\n return renderer(scope, options);\n },\n start: function(){\n var autorender = this;\n new Zone({\n plugins: [xhrZone, systemImportZone]\n }).run(function(){\n var state = autorender.state = new autorender.viewModel;\n var docEl = document.documentElement;\n domData.set.call(docEl, "viewModel", state);\n\n route.data = state;\n route.ready();\n\n autorender.rerender();\n });\n },\n rerender: function(){\n var keep = { "SCRIPT": true, "STYLE": true, "LINK": true };\n function eachChild(parent, callback){\n var nodes = makeArray(parent), node;\n var i = 0, len = nodes.length;\n\n for(; i < len; i++) {\n node = nodes[i];\n if(!keep[node.nodeName]) {\n if(callback(node) === false) {\n break;\n }\n }\n }\n }\n\n function remove(el) {\n mutate.removeChild.call(el.parentNode, el);\n }\n\n function appendTo(parent){\n return function(el){\n mutate.appendChild.call(parent, el);\n }\n }\n\n function traverse(node, tagName){\n var child;\n eachChild(node, function(el){\n if(el.tagName === tagName) {\n child = el;\n return false;\n } else {\n child = traverse(el, tagName);\n return !child;\n }\n });\n return child;\n }\n\n this.renderAsync().then(function(result){\n var frag = result.fragment;\n var head = document.head || document.getElementsByTagName("head")[0];\n var body = document.body;\n\n // Move elements from the fragment\'s head to the document head.\n eachChild(head, remove);\n\n var fragHead = traverse(frag, "HEAD");\n eachChild(fragHead, appendTo(head));\n\n // Move elements from the fragment\'s body to the document body.\n eachChild(body, remove);\n\n var fragBody = traverse(frag, "BODY");\n eachChild(fragBody, appendTo(body));\n });\n },\n renderAsync: function(renderer, data, options, doc){\n renderer = renderer || this.renderToFrag;\n data = data || this.state;\n options = options || {};\n\n var frag;\n\n var zone = new Zone({\n plugins: [xhrZone, systemImportZone]\n });\n\n return zone.run(function(){\n frag = renderer(data, options);\n\n if(doc) {\n var oldDoc = can.document;\n can.document = doc;\n mutate.appendChild.call(doc.body, frag, doc);\n can.document = oldDoc;\n }\n }).then(function(zoneData){\n return {\n fragment: frag,\n zoneData: zoneData\n };\n });\n },\n legacy: false,\n render: function(doc, state){\n var renderer = this.renderToFrag;\n var frag = renderer(state, {});\n\n var oldDoc = can.document;\n can.document = doc;\n mutate.appendChild.call(doc.body, frag, doc);\n can.document = oldDoc;\n },\n ' + ((__t = ( ases )) == null ? '' : __t) + '\n };\n var isNW = (function(){\n try{var nr = System._nodeRequire; return nr && nr(\'nw.gui\') !== \'undefined\';}catch(e){return false;}\n })();\n\n if(typeof steal !== \'undefined\' && (isNW || !isNode))\n steal.done().then(function() {\n if(steal.System.autorenderAutostart !== false) {\n autorender.start();\n }\n });\n\n return autorender;\n});\n'; diff --git a/src/template.txt b/src/template.txt index 4370b05..97a0da2 100644 --- a/src/template.txt +++ b/src/template.txt @@ -50,7 +50,6 @@ define(<%= imports %>, function(<%= args %>){ plugins: [xhrZone, systemImportZone] }).run(function(){ var state = autorender.state = new autorender.viewModel; - var docEl = document.documentElement; domData.set.call(docEl, "viewModel", state); diff --git a/test/autorender_test.js b/test/autorender_test.js index e612c08..dba6fdc 100644 --- a/test/autorender_test.js +++ b/test/autorender_test.js @@ -1,7 +1,7 @@ var QUnit = require("steal-qunit"); var F = require("funcunit"); -require("./unit"); +//require("./unit"); F.attach(QUnit); diff --git a/test/basics/test.html b/test/basics/test.html index 145fe29..1fa41ea 100644 --- a/test/basics/test.html +++ b/test/basics/test.html @@ -5,6 +5,8 @@ @@ -13,9 +15,15 @@ var canViewModel = require("can-view-model"); var Zone = require("can-zone"); - new Zone().run(function() { - return System.import('test/basics/index.stache!done-autorender'); - }).then(function() { + System.import('test/basics/index.stache!done-autorender') + .then(function(){ + return new Promise(function(resolve, reject){ + setTimeout(function(){ + resolve(); + }, 500); + }); + }) + .then(function() { var vm = canViewModel(document.documentElement); if(window.QUnit) {